CaCore In Geworkbench
From Informatics
See also: caCore
When Integrating caCore in geWorkbench, we ran into a classloading issue. The situation and resolution are outlined below
- Each component as well as the core should be running in its own thread.
- This way, when Thread.currentThread.getContextClassLoader() is called in a component, the component code will have access to the resources.
The issue we were seeing was as follows:
- Component A
- Contains spring.jar
- Component B
- Contains spring.jar
When component A is loaded, its classloader will load all the classes as well as jars (including the classes in spring.jar).
When component B is loaded, its classloader will load all the classes as well as jars (again, including the classes in spring.jar).
When code in spring.jar does a Thread.currentThread.getContextClassLoader(), the thread returned is the thread of the core, hence the reason why classes in the component spring.jar could be found. To alleviate this, we set the class loader in the ApplicationContextServiceClientImpl to be the class loader of the component so when spring does a Thread.currentThread, it now gets the classloader of the component.
One thing to consider would be to load each component in a separate thread, so if third parties try and access the current thread (and underlying resources), they are in fact staying within the “sandbox” of the component. This, however, needs to be done very carefully and will require some time.