You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Cory Wilkerson <cw...@travelnow.com> on 2003/01/27 18:38:33 UTC
MessageContext
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;
}
Re: MessageContext
Posted by Jess Sightler <js...@eximtechnologies.com>.
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
=======================================