[weld-dev] @ThreadScoped for Weld SE

Dan Allen dan.j.allen at gmail.com
Thu Dec 10 20:01:21 EST 2009


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 at 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 at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/weld-dev/attachments/20091210/ae7dc58c/attachment.html 


More information about the weld-dev mailing list