That&#39;s a cool idea. It more or less brings ThreadLocal in line with the CDI scoping mechanism, correct?<br><br>I would think this would be useful even in Java EE because you could use it for async threads, I suppose. A specific usage scenario isn&#39;t coming to me at the moment.<br>
<br>-Dan<br><br><div class="gmail_quote">On Thu, Dec 10, 2009 at 7:45 PM, Peter Royle <span dir="ltr">&lt;<a href="mailto:howardmoon@screamingcoder.com">howardmoon@screamingcoder.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
I&#39;ve implemented ThreadContext and @ThreadScoped (revision 5267) for Weld SE.<br>
<br>
Quick example:<br>
<br>
---<br>
public class DateFormatterProducer {<br>
<br>
   /** Produces a thread-safe date formatter (one instance per thread).    */<br>
   @Produces @ThreadScoped<br>
   public SimpleDateFormat dateFormat()  {<br>
      return new SimpleDateFormat(&quot;yyyyMMdd HHmm&quot;);<br>
   }<br>
}<br>
---<br>
public class ThreadThing implements Runnable {<br>
   @Inject SimpleDateFormat dateFormat;<br>
   public void run() {<br>
        ...<br>
        dateFormat.format(date);<br>
        ...<br>
   }<br>
}<br>
---<br>
public class MainClass {<br>
<br>
   public void main(@Observes ContainerInitialized, Instance&lt;ThreadThing&gt; threadThing, WeldContainer weld) {<br>
      Thread thread1 = new Thread(threadThing.select().get());<br>
      thread1.start();<br>
<br>
      Thread thread2 = new Thread(threadThing.select().get());<br>
      thread2.start();<br>
<br>
      thread1.join();<br>
      thread2.join();<br>
<br>
      weld.shutdown();<br>
   }<br>
<br>
}<br>
--- requires this decorator to be enabled ---<br>
&lt;beans&gt;<br>
   &lt;decorators&gt;<br>
      &lt;decorator&gt;org.jboss.weld.environment.se.threading.RunnableDecorator&lt;/decorator&gt;<br>
   &lt;/decorator&gt;<br>
&lt;/beans&gt;<br>
<br>
Anyone please let me know how you think this could be improved.<br>
<br>
Thanks,<br>
<br>
Pete R.<br>
<br>
<br>
<br>
_______________________________________________<br>
weld-dev mailing list<br>
<a href="mailto:weld-dev@lists.jboss.org">weld-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/weld-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/weld-dev</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Dan Allen<br>Senior Software Engineer, Red Hat | Author of Seam in Action<br>Registered Linux User #231597<br><br><a href="http://mojavelinux.com">http://mojavelinux.com</a><br>
<a href="http://mojavelinux.com/seaminaction">http://mojavelinux.com/seaminaction</a><br><a href="http://www.google.com/profiles/dan.j.allen">http://www.google.com/profiles/dan.j.allen</a><br>