That's a cool idea. It more or less brings ThreadLocal in line with the CDI scoping mechanism, correct?

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't coming to me at the moment.

-Dan

On Thu, Dec 10, 2009 at 7:45 PM, Peter Royle <howardmoon@screamingcoder.com> wrote:
Hi,

I've implemented ThreadContext and @ThreadScoped (revision 5267) for Weld SE.

Quick example:

---
public class DateFormatterProducer {

  /** Produces a thread-safe date formatter (one instance per thread).    */
  @Produces @ThreadScoped
  public SimpleDateFormat dateFormat()  {
     return new SimpleDateFormat("yyyyMMdd HHmm");
  }
}
---
public class ThreadThing implements Runnable {
  @Inject SimpleDateFormat dateFormat;
  public void run() {
       ...
       dateFormat.format(date);
       ...
  }
}
---
public class MainClass {

  public void main(@Observes ContainerInitialized, Instance<ThreadThing> threadThing, WeldContainer weld) {
     Thread thread1 = new Thread(threadThing.select().get());
     thread1.start();

     Thread thread2 = new Thread(threadThing.select().get());
     thread2.start();

     thread1.join();
     thread2.join();

     weld.shutdown();
  }

}
--- requires this decorator to be enabled ---
<beans>
  <decorators>
     <decorator>org.jboss.weld.environment.se.threading.RunnableDecorator</decorator>
  </decorator>
</beans>

Anyone please let me know how you think this could be improved.

Thanks,

Pete R.



_______________________________________________
weld-dev mailing list
weld-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/weld-dev



--
Dan Allen
Senior Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597

http://mojavelinux.com
http://mojavelinux.com/seaminaction
http://www.google.com/profiles/dan.j.allen