Yeah...I just ran across that in the source -- agreed -- ThreadLocal is very cool.  Of 
course, that said, I suppose I can't spin off a separate thread and expect to be able 
to use MessageContext.getCurrentContext() with any reliability.

Cory

-----Original Message-----
From: Jess Sightler [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 27, 2003 12:06 PM
To: [EMAIL PROTECTED]
Subject: Re: MessageContext


Hi Cory,

My understanding is that this is thread-safe, because
MessageContext.getCurrentContext() uses a ThreadLocal variable to get
the current context (so each separate thread would "see" the correct
variable only for it's current thread).

ThreadLocal is very cool. :)


On Mon, 2003-01-27 at 12:38, Cory Wilkerson wrote:
> Is the following thread safe?  The fact that this is a static method scares me a 
>bit, ie, will MessageContext.getCurrentContext() hold true in situations like this or 
>is it possible that as two threads enter this method simultaneously...things could 
>get a little funky.
> 
> 
>  public static RequestHandler getInstance() {
>         RequestHandler handler = null;
> 
>         MessageContext mc = MessageContext.getCurrentContext();
>         if (mc != null && mc.getService() != null) {
>             String serviceName = mc.getService().getName();
>             if (serviceName != null) {
>                 if (serviceName.equalsIgnoreCase("SomeServiceName")) {
>                     handler = new TNowAirHandler();
>                 }
>             }
>         }
> 
>         return handler;
>     }
-- 
=======================================
Jess Sightler
Senior Developer
Exim Technologies
131 Falls Street
Greenville SC 29601
Phone: 864-679-4651
=======================================



Reply via email to