2 Replies Latest reply on Mar 11, 2015 1:21 PM by Maciej Swiderski

    Concurrent instantiation of Runtime Environments

    akoskm Newbie

      Hello!

       

      I have a simple Unit test which I expected to work, but instead I'm getting some unrelated exceptions complaining about TimerService. I don't have any timers in my bpmn file.

      The complete files are attached but basically I'm only trying to create two RuntimeEnvironment simultaneously.

       

      Exception in thread "second" java.lang.IllegalStateException: java.lang.reflect.InvocationTargetException
        at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:164)
        at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.newKieSession(KnowledgeStoreServiceImpl.java:70)
        at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.newKieSession(KnowledgeStoreServiceImpl.java:39)
        at org.kie.internal.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:121)
        at org.jbpm.runtime.manager.impl.factory.JPASessionFactory.newKieSession(JPASessionFactory.java:42)
        at org.jbpm.runtime.manager.impl.SingletonRuntimeManager.init(SingletonRuntimeManager.java:95)
        at org.jbpm.runtime.manager.impl.RuntimeManagerFactoryImpl.newSingletonRuntimeManager(RuntimeManagerFactoryImpl.java:71)
        at com.example.test.jbpm.HTWithConcurrentRuntimesTest$HumanTaskResolver.getRuntimeManager(HTWithConcurrentRuntimesTest.java:90)
        at com.example.test.jbpm.HTWithConcurrentRuntimesTest$HumanTaskResolver.run(HTWithConcurrentRuntimesTest.java:57)
        at java.lang.Thread.run(Thread.java:745)
      Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:150)
        ... 9 more
      Caused by: java.lang.IllegalArgumentException: Timer service 'new org.jbpm.process.core.timer.impl.RegisteredTimerServiceDelegate("exec-2-timerServiceId")' not found
        at org.drools.core.SessionConfiguration.newTimerService(SessionConfiguration.java:495)
        at org.drools.core.time.TimerServiceFactory.getTimerService(TimerServiceFactory.java:27)
        at org.drools.core.impl.StatefulKnowledgeSessionImpl.<init>(StatefulKnowledgeSessionImpl.java:366)
        at org.drools.core.impl.StatefulKnowledgeSessionImpl.<init>(StatefulKnowledgeSessionImpl.java:278)
        at org.drools.core.common.PhreakWorkingMemoryFactory.createWorkingMemory(PhreakWorkingMemoryFactory.java:21)
        at org.drools.core.impl.KnowledgeBaseImpl.newStatefulSession(KnowledgeBaseImpl.java:1304)
        at org.drools.core.impl.KnowledgeBaseImpl.newStatefulSession(KnowledgeBaseImpl.java:1289)
        at org.drools.core.impl.KnowledgeBaseImpl.newStatefulKnowledgeSession(KnowledgeBaseImpl.java:292)
        at org.drools.core.impl.KnowledgeBaseImpl.newKieSession(KnowledgeBaseImpl.java:378)
        at org.drools.persistence.SingleSessionCommandService.initNewKnowledgeSession(SingleSessionCommandService.java:125)
        at org.drools.persistence.SingleSessionCommandService.<init>(SingleSessionCommandService.java:92)
        ... 14 more
      Caused by: [Error: could not instantiate class: null]
      [Near : {... new org.jbpm.process.core.timer.im ....}]
                       ^
      [Line: 1, Column: 5]
        at org.mvel2.ast.NewObjectNode.getReducedValue(NewObjectNode.java:307)
        at org.mvel2.MVELInterpretedRuntime.parseAndExecuteInterpreted(MVELInterpretedRuntime.java:106)
        at org.mvel2.MVELInterpretedRuntime.parse(MVELInterpretedRuntime.java:49)
        at org.mvel2.MVEL.eval(MVEL.java:92)
        at org.drools.core.util.MVELSafeHelper$RawMVELEvaluator.eval(MVELSafeHelper.java:406)
        at org.drools.core.SessionConfiguration.newTimerService(SessionConfiguration.java:493)
        ... 24 more
      Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at org.mvel2.ast.NewObjectNode.getReducedValue(NewObjectNode.java:278)
        ... 29 more
      Caused by: java.lang.IllegalStateException: TimerService with key exec-2-timerServiceId was not found in the registry
        at org.jbpm.process.core.timer.impl.RegisteredTimerServiceDelegate.<init>(RegisteredTimerServiceDelegate.java:59)
        ... 34 more
      
      
      

       

      Relevant parts of my code (full sources are attached):

      @Test
      public void humanTaskTest() throws Exception {
        HumanTaskResolver htr1 = new HumanTaskResolver(1);
         HumanTaskResolver htr2 = new HumanTaskResolver(2);
      
         Thread t1 = new Thread(htr1, "first");
         Thread t2 = new Thread(htr2, "second");
      
         t1.start();
         t2.start();
      
         t1.join();
         t2.join();
      }
      
      
      

      HumanTaskResolver:

      class HumanTaskResolver implements Runnable {
      
         private final long pid;
      
        public HumanTaskResolver(long pid) {
         this.pid = pid;
         }
      
         @Override
         public void run() {
        RuntimeManager manager = getRuntimeManager("process/humantask/SimpleHumanTask.bpmn");
         manager.close();
         }
      
         private RuntimeManager getRuntimeManager(String process) {
        Properties properties = new Properties();
         properties.setProperty("some_group", "");
      
         UserGroupCallback userGroupCallback = new JBossUserGroupCallbackImpl(properties);
         // load up the knowledge base
      
         KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
         kbuilder.add(ResourceFactory.newClassPathResource(process), ResourceType.BPMN2);
      
         RuntimeEnvironment environment = RuntimeEnvironmentBuilder.getDefault()
        .persistence(true)
        .entityManagerFactory(emf)
        .userGroupCallback(userGroupCallback)
        .knowledgeBase(kbuilder.newKnowledgeBase())
        .registerableItemsFactory(new DefaultRegisterableItemsFactory() {
         @Override
         public List<TaskLifeCycleEventListener> getTaskListeners() {
        List<TaskLifeCycleEventListener> defaultListeners = new ArrayList<>();
         defaultListeners.add(new JPATaskLifeCycleEventListener());
         // add any custom listeners
         defaultListeners.addAll(super.getTaskListeners());
         // add listeners from deployment descriptor
         defaultListeners.addAll(getTaskListenersFromDescriptor());
      
        return defaultListeners;
         }
        })
        .get();
        return RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment, "exec-" + pid);
         }
      }
      
      
      

      Sorry for the indentation but your inline code editor makes it unable to edit the code I pasted.