Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-13391

getContextClassLoader is null in Managed thread factory

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • 18.0.1.Final, 19.0.0.Final
    • Concurrency Utilities
    • None
    • Hide

      In our code where we are getting class loader, Rather than using context class loader we are trying to get the current objects class loader and setting it to current threads class loader and in finally block resetting the class loader to original value.

      try {
          final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
          if (classLoader == null) {
                Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
          }
          clazz = Class.forName(className, true, classLoader);
      } catch (final Exception e) {
          throw new JbpmClassNotFoundException("couldn't load class " + className, e);
      } finally {
          Thread.currentThread().setContextClassLoader(classLoader);
      }
      

      We don't know the consequence of this work around to our application.

      Show
      In our code where we are getting class loader, Rather than using context class loader we are trying to get the current objects class loader and setting it to current threads class loader and in finally block resetting the class loader to original value. try { final ClassLoader classLoader = Thread .currentThread().getContextClassLoader(); if (classLoader == null ) { Thread .currentThread().setContextClassLoader( this .getClass().getClassLoader()); } clazz = Class .forName(className, true , classLoader); } catch ( final Exception e) { throw new JbpmClassNotFoundException( "couldn't load class " + className, e); } finally { Thread .currentThread().setContextClassLoader(classLoader); } We don't know the consequence of this work around to our application.

    Description

      We are using managed-thread-factory and Threads belong to this do not have context class loader associated with it

      <managed-thread-factories>
          <managed-thread-factory name="FlowWorkManagerThreadFactory" jndi-name="java:jboss/ee/concurrency/factory/FlowWorkManagerThreadFactory" context-service="default"/>
      </managed-thread-factories>
      <managed-executor-services>
          <managed-executor-service
              name="InteractiveWorkflowWorkManagerExecutorService"
              jndi-name="java:jboss/ee/concurrency/executor/FLOW_MANAGEDEXECUTOR"
              core-threads="${threadpool.interactiveWorkflow.minthread}"
              max-threads="${threadpool.interactiveWorkflow.maxthread}" keepalive-time="5000"
              queue-length="${threadpool.interactiveWorkflow.queuesize}"
              thread-factory="FlowWorkManagerThreadFactory"
              hung-task-threshold="600000" />
      </managed-executor-services>
      

      classLoader variable in below code

      final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
      

      evaluates as null when called inside managed thread.

      Same code works fine with Wildfly 16 and Wildfly 17.0.1

      In 16 and 17.0.1 The class loader is from Service module loader.

      Server logs with org.jboss.as.ee in TRACE level for Wildfly 16, 17.0.1 and 18 are attached.

      Attachments

        1. WildFly-16-server.log
          220 kB
        2. WildFly-17-server.log
          207 kB
        3. WildFly-18-server.log
          217 kB

        Activity

          People

            emartins@redhat.com Eduardo Martins
            dheeraj.madhu@gmail.com Dheeraj Joshi (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: