I’m running the java application using tomcat7.
I need to store the information per tomcat thread, so I can use the ThreadLocals approach.
In my server.xml the threadpool definition looks like the following:
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="10000" minSpareThreads="2000"/>
I have a class EnhanceThread
public class EnhanceThread extends Thread {
...
@Override
public void run() {
SomeThreadLocals.set(data);
super.run();
}
}
How can I override the tomcat thread pool definition and make it use use my class?
Is there a better approach to threat this problem?
You don’t need to mess with Tomcat threads for that. Just use the following code:
Each time you need a serializer, call
JsonSerializerFactory.get(), and it will return the thread-local instance, and lazily create it if it doesn’t exist yet.