5 Replies Latest reply on Sep 30, 2008 12:52 PM by Bernd Ruecker

    Initialise thread context classloader

    Bernd Ruecker Master


      I am working on https://jira.jboss.org/jira/browse/JBPM-1448 (jBPM does not initialize thread context classloader).

      First of all, why I want to do this: This enables you to put Interfaces or other stuff used in your action classes in the par, so they end up in the database. Because the ProcessClassLoader will become ContextClassLoader it is used to load everything correctly...

      But this is only half the way I want to go. Image you put jbpm in your app-server (or ESB) once, but have different applications (ear, esb, ...) using it. Now I write an own small MBean, which is a registry where processes register which class loaders are responsible for "their" action classes. My own ProcessClassLoader now also looks in this registry and by doing so, it can even load action classes or other stuff correctly from the right EAR, even if a process was maybe started by the web-console, not knowing the ear... But more on this idea later.

      Back to setting the ContextClassLoader. My approach to implement it is adding this code

      ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
      try {
       .... existing code ...
      finally {

      to the following methods:
      - Action.execute
      - Decision.execute
      - TaskController.initializeVariables
      - TaskController.submitParameters
      - AssignmentHandler.performAssignmentDelegation

      On all these places I have the ProcessDefinition on hand, so it is possible to do... These are all places I found where the ProcessClassLoader is used and all Delegation use cases I remembered. So it is not too much work to do and consistent overall in jBPM (not like the proposed workaround to build an own base action class where the context class loader is set).

      What do you guys think?