Per Thread Class Loader... what do you think? 2007-08-05 - By Johnny Kewl
Back public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//=======new DoServiceClass().doService(request, response)========
ClassLoader origClassLoader = Thread.currentThread() .getContextClassLoader(); ExClassLoader localClassLoader = new ExClassLoader(origClassLoader); String repository = dock.getRepository(); localClassLoader.setRepository(repository); Thread.currentThread().setContextClassLoader(localClassLoader); doServiceMain(request, response);
Thread.currentThread().setContextClassLoader(origClassLoader); //====================================================== }
This snippet of code is actually wrapped in new DoServiceClass().doService (request, response) for thread safety reasons. ie in doPost.... this is called new DoServiceClass().doService(request, response); But its shown as above because its "easier" to appreciate the complexity of whats actually happening.
What is does is swap Tomcats classloader, to an Extended class loader... on every thread.... and then after processing the thread gives TC its own class loader back. It seems to work, but its seriously complex stuff, I'm building a per thread container on top of TC's container, and I'm wondering if this is the right way to do it. More I think about this...... more confused I get....
|
|