Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

ThreadLocal implementation problem

Abiel Hakeem
1 decade ago Mar 22, 2012 5:46am
Teemu Pöntelin
1 decade ago Mar 22, 2012 9:08am

My first guess would be that you have declared some variable as static and therefore are sharing that with all application instances. In the typical case there should be no need to create separate threads for accessing the database.

Last updated on Mar, 22nd 2012
Henri Sara
1 decade ago Mar 22, 2012 9:37am

Abiel Hakeem: I have a problem with my implementation of ThreadLocal. When I populate a table with data loaded from JDBC SQL Query, sometimes another instance of application is displaying another instance's query result, this is happen when the query is slow. I think when Connection object is instantiated in a threadlocal vaadin application, it should also have unique thread, so different query will be processed, and it should have not display another query from another connection., but since each thread process different query string, can it use different query result processed from another Connection object from another ThreadLocal application instance?

Note also that application servers are reusing the same threads from a pool to serve all requests from all users. Therefore, any ThreadLocal variables (for non-background threads) should be set at the beginning of every request and ideally also cleared at the end of the request. This can be done e.g. with an HttpServletRequestListener or a TransactionListener.

I'm not sure if this is the issue here, but something to be aware of at least.

Abiel Hakeem
1 decade ago Mar 22, 2012 2:30pm
Henri Sara
1 decade ago Mar 29, 2012 7:16am
Bobby Bissett
1 decade ago Apr 19, 2012 4:13pm