threadlocal

ThreadLocals hard to use

I'm using ThreadLocal variables (through Clojure's vars, but the following is the same for plain ThreadLocals in Java) and very often run into the issue that I can't be sure that a certain code path will be taken on the same thread or on another thread. For code under my control this is obviously not too big a problem, but for polymorphi...

What are the pros and cons of using an in memory DB rather than a ThreadLocal

we have been using ThreadLocal so far to carry some data so as to not clutter the API. However below are some of issues of using thread local that which I dont like 1) over the years the data items being carried in thread local has increased 2) Since we started using threads (for some light weight processing), we have also migrating the...

Why does every thread in my application use a different hibernate session?

Hi, I have a web-application which uses hibernate and for some reason every thread (httprequest or other threads related to queueing) uses a different session. I've implemented a HibernateSessionFactory class which looks like this: public class HibernateSessionFactory { private static final ThreadLocal<Session> threadLocal = new ThreadL...

Is there no way to iterate over or copy all the values of a Java ThreadLocal?

Context: static ThreadLocal<MyType> threadLocalMyType = ... What i'd like is to say something like: for (ThreadLocalEntry e: threadLocalMyType.getMapLikeThing() { // Thread t = e.getKey(); // I don't need the thread value right now, but it might be useful for // something else. MyType theMyType = e.getValue(); ...

Good way to make Authentication and Authorization information available between application layers

I have a web application running on Google App Engine (GAE) for JAVA. I'm authenticating the client at the Servlet layer but would like to make the client information available to my business and data layers without having to pass the client object through the arguments of every single function. I'm considering setting up a "session"...

Connection Pooling vs Per-Thread JDBC Connection

Which of these approaches is better: connection pooling or per-thread JDBC connections? ...

ThreadLocal on Google App Engine (GAE)

I would like to make some request-wide data available in my app engine application. Examples: The URL for which the request was made. Authentication information. I see that ThreadLocal is on the whitelist: http://code.google.com/appengine/docs/java/jrewhitelist.html Is ThreadLocal a good and safe way to make this information avai...

Threadlocal reference to hibernate session impl, causing session impl not to get garbage collected

Hello, I am using thread local to manage my hibernate sessions. Recently I have been seeing OutOfMemory exceptions on my production server. I ran Eclipse MAT on the heap_dump and saw a lot of my sessions are not getting garbage collected even though they are being closed due to them being referenced by tomcatse ThreadWithAttributes obje...

How to use ThreadLocal within Hibernate by Spring

Hello everyone, Currently we use a session per Operation (anti-) Pattern with Hibernate/Spring for our Swing client/server application. The application grew and requests got more and more complex, which resulted in bad performance issues. Because of that, we decided to reuse the session for complex requests, which need to perform more r...

ThreadStatic vs. ThreadLocal<T> Performance

I recently read this post about poor performance of fields marked ThreadStatic - they're apparently 60x slower than normal field access. Does .NET 4's ThreadLocal< T > perform any better? Are there any alternatives that offer high performance thread-specific storage? ...

How to clean up threadlocals

Does any one has an example how to do this? or are they handled by the garbage collector? im using tomcat6 ...

JMS usage in a JSE application

Hi, I have a JSE application which currently uses JMS, it was written by a developer which is no longer with the company. For some reason, I really don't know if it was justified or not, the JMS session were not created as transacted. I now want to change this as to have all Producers using transacted sessions; This in itself is very sim...

Lots of ThreadLocalMap entries in memory

Consider a very large Java VM with a great many threads running a web server. Now consider a sample of the output generated by jmap -histo that looks something like this: 4: 5989163 191653216 java.lang.ThreadLocal$ThreadLocalMap$Entry 10: 46786 49012000 [Ljava.lang.ThreadLocal$ThreadLocalMap$Entry; 86: ...