ThreadLocal considerations. Use in WebSphere 6 and Weblogic 10.

ThreadLocal class enables the sharing of a variable in a statically way across a whole Java process by attaching this variable to a single Thread (p.e. Thread.currentThread()). This is specially useful to make accesible values recovered in filter layer to the other ones.

Think about database logging of HTTP requests or responses. Note that this is the unique point to retrieve, for instance, complete signed requests or responses. All this process (request and response) is executed on a single thread, so ThreadLocal mechanism can be used to share the request content with the DAO layer. By doing a threadLocal.set(request) on Filter class and a threadLocal.get() on DAO class the described functionality is achieved.

And here is where different behaviours arrive. WebSphere 6 doesn’t clean servlet pooled threads after execution while Weblogic 10 does. So, ThreadLocal variable must be cleared in WebSphere for every new request!

Typically is discouraged the use of this tecnique in managed environments, but in many cases the best should be the simpliest.

Reference – IBM – Threading lightly.


Un comentario en “ThreadLocal considerations. Use in WebSphere 6 and Weblogic 10.

  1. Where did you find the mention that WebSphere doesn’t clear
    the ThreadLocal variable ? I couldn’t find it the IBM – Threading lightly link.



Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de

Estás comentando usando tu cuenta de Cerrar sesión /  Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )


Conectando a %s