JobAcquisitionThread and JobExecutor

17 posts / 0 new
Last post
pganga
Offline
Last seen: 1 year 9 months ago
Joined: 02/16/2012 - 20:51
Posts: 8
JobAcquisitionThread and JobExecutor

Hi Guys,
We are trying to replace the default job executor for a custom one that will use spring and the application server thread pool (commonj Work Manager). So we don't use any unmanaged threads.
Reviewing the code we notice that is using another unmanaged thread the one polling for available jobs (JobAcquisitionThread).
It is there a way to replace that component easily?
Which will be the best strategy to follow in this case?.

Thanks in advance.

Bardioc
Offline
Last seen: 1 month 2 weeks ago
Joined: 09/06/2011 - 08:10
Posts: 31

I've implemented this for both, the JobAquisitionThread and the actual job executor for commonj, because WebSphere Application Server does not like it at all, if threads are created without its knowledge. Actually I've rewritten the JobAquisitionThread to use the commonj TimerManager and the Job Executor to use the commonj WorkManager, both configurable via JNDI.

I'm currently trying to find a generalizable way to support different JobExecutor threading models, because other Appservers have different approches for this. There has been some work done already by Ronald van Kuijk (see ACT-34), but I'm unsure how fast this will be integrated.

My solution simply overrides the current JobExecutor (simple extend) in a programmatically done configuration of the Activiti Engine.

If interested I can explain in more detail how I've implemented this.

Maybe Ronald van Kuijk can shed some light on his previous work for ACT-34 and explain if the modifications done so far will somehow be included in Activity soon.

Regards,

Heiko

pganga
Offline
Last seen: 1 year 9 months ago
Joined: 02/16/2012 - 20:51
Posts: 8

Hey Bardioc
I really appreciate your answer.
I was actually doing exactly that, extending the job executor and inside this one injecting a TaskExecutor.
This Task executor is configured trough spring and in development is just a simple ThreadPoolTaskExecutor but in
WAS is a WorkManagerTaskExecutor that will use the Threadpoll JNDI name to access it.

Quote:

If interested I can explain in more detail how I've implemented this.

Please I am really interested in seeing your approach.

Thanks again.

meyerd
Offline
Last seen: 1 year 2 months ago
Joined: 11/27/2010 - 20:47
Posts: 151

Just as an FYI, we have this ready in camunda fox with commercial support for webshere.

Daniel Meyer
Activiti developer

camunda services GmbH
Providing Activiti Training & Consulting:
http://www.camunda.com/activiti
Providing stable and supported distributions of Activiti:
http://www.camunda.com/fox
Our Blog: http://www.bpm-guide.de

Bardioc
Offline
Last seen: 1 month 2 weeks ago
Joined: 09/06/2011 - 08:10
Posts: 31

meyerd wrote:
Just as an FYI, we have this ready in camunda fox with commercial support for webshere.

Sounds great, allthough I think something like this, except the commercial support, should be part of Activiti itself. Right now it is not really compatible with application server in general. From my perspective the core embeddable engine is not really embeddable because of the lacking support for managed threads. These are necessary in almost all application servers and something we should include in Activiti.

Just my two cents smiley

Heiko

PS: The company I'm working for might consider Camunda Fox, because of the commercial support. I'll check into that and get in touch with you guys.

Bardioc
Offline
Last seen: 1 month 2 weeks ago
Joined: 09/06/2011 - 08:10
Posts: 31

pganga wrote:
Hey Bardioc
I really appreciate your answer.
I was actually doing exactly that, extending the job executor and inside this one injecting a TaskExecutor.
This Task executor is configured trough spring and in development is just a simple ThreadPoolTaskExecutor but in
WAS is a WorkManagerTaskExecutor that will use the Threadpoll JNDI name to access it.

Quote:

If interested I can explain in more detail how I've implemented this.

Please I am really interested in seeing your approach.

Thanks again.

I'll try to get those files and make them available as attachment to a note and PM you!

sebastian.s
Offline
Last seen: 9 months 3 weeks ago
Joined: 05/17/2010 - 09:21
Posts: 71

Hello Heiko,

I could also use these files and would be happy if you could pm me, too.

Thanks in advance

Sebastian

Sebastian
Some call it Europe - I call it home.

pganga
Offline
Last seen: 1 year 9 months ago
Joined: 02/16/2012 - 20:51
Posts: 8

Quote:

I'll try to get those files and make them available as attachment to a note and PM you!

Great Thanks!, I'll be waiting.

Bardioc
Offline
Last seen: 1 month 2 weeks ago
Joined: 09/06/2011 - 08:10
Posts: 31

Hello again,

attached you find a maven project [attachment=1]activiti-websphere.zip[/attachment] that contains the support for WebSphere Application Server. It implements a custom Activiti Configuration based on the Spring Configuration object. The use of Spring here is important, as WebSphere contains a specific Transaction Manager support by using so called Units-of-Work. Spring provides support for this. The attached xml configuration [attachment=0]activiti.cfg.xml.zip[/attachment] shows how to use it.

Make sure you have included the dependency for activiti-spring as well, as it is mandatory for this. The only additional configuration parameter for WebSphere is the workManager JNDI-Name.

<beans xmlns="http://www.springframework.org/schema/beans" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans <a href="http://www.springframework.org/schema/beans/spring-beans.xsd">
 
" rel="nofollow">http://www.springframework.org/schema/beans/spring-beans.xsd">
 
</a>	<bean id="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager" />
 
    <bean id="processEngineConfiguration" class="org.activiti.websphere.WebSphereEngineConfiguration">     
        <property name="transactionManager"  ref="transactionManager" />
        <property name="jobExecutorWorkManagerJndiName" value="java:comp/env/wm/default" /> 
    </bean>
</beans>

It donates the JNDI name of the WorkManager to be used. It is optional, and if not specified, the given default value is used.

For the maven project to compile successfully, you need to provide an IBM specific reference to the com.ibm.ws.prereq.commonj-twm.jar-File, which contains the API code for the WorkManagers. You find this file in your WebSphere application servers 'plugin' directory and need to install it into your local repository:

mvn install:install-file -Dfile=com.ibm.ws.prereq.commonj-twm.jar -DgroupId=com.ibm.ws.prereq -DartifactId=commonj-twm -Dversion=1.1 -Dpackaging=jar

The implementation uses an ExecutionService for WorkManagers. The idea came to me while I saw that the default JobExecutor uses the ThreadPoolExecutor.

Attention: This module will only work for Activiti 5.9 or above, as the modifications introduced by JIRA ACT-34 are necessary.

The code is free of use. I would like to get a note if you find a mistake, error or something that could be done better.

Best regards,

Heiko

pganga
Offline
Last seen: 1 year 9 months ago
Joined: 02/16/2012 - 20:51
Posts: 8

Bardioc wrote:
Hello again,

attached you find a maven project [attachment=1]activiti-websphere.zip[/attachment] that contains the support for WebSphere Application Server. It implements a custom Activiti Configuration based on the Spring Configuration object. The use of Spring here is important, as WebSphere contains a specific Transaction Manager support by using so called Units-of-Work. Spring provides support for this. The attached xml configuration [attachment=0]activiti.cfg.xml.zip[/attachment] shows how to use it.

Make sure you have included the dependency for activiti-spring as well, as it is mandatory for this. The only additional configuration parameter for WebSphere is the workManager JNDI-Name.

<beans xmlns="http://www.springframework.org/schema/beans" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans <a href="http://www.springframework.org/schema/beans/spring-beans.xsd">
 
" rel="nofollow">http://www.springframework.org/schema/beans/spring-beans.xsd">
 
</a>	<bean id="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager" />
 
    <bean id="processEngineConfiguration" class="org.activiti.websphere.WebSphereEngineConfiguration">     
        <property name="transactionManager"  ref="transactionManager" />
        <property name="jobExecutorWorkManagerJndiName" value="java:comp/env/wm/default" /> 
    </bean>
</beans>

It donates the JNDI name of the WorkManager to be used. It is optional, and if not specified, the given default value is used.

For the maven project to compile successfully, you need to provide an IBM specific reference to the com.ibm.ws.prereq.commonj-twm.jar-File, which contains the API code for the WorkManagers. You find this file in your WebSphere application servers 'plugin' directory and need to install it into your local repository:

mvn install:install-file -Dfile=com.ibm.ws.prereq.commonj-twm.jar -DgroupId=com.ibm.ws.prereq -DartifactId=commonj-twm -Dversion=1.1 -Dpackaging=jar

The implementation uses an ExecutionService for WorkManagers. The idea came to me while I saw that the default JobExecutor uses the ThreadPoolExecutor.

Attention: This module will only work for Activiti 5.9 or above, as the modifications introduced by JIRA ACT-34 are necessary.

The code is free of use. I would like to get a note if you find a mistake, error or something that could be done better.

Best regards,

Heiko

Thank you very much.
I'll review and try to get ideas for my own stuff, also I will provide the requested feedback as well.

heymjo
Offline
Last seen: 1 year 1 month ago
Joined: 02/01/2011 - 10:19
Posts: 143

Hello Heiko,

I have tested your CommonJ interface code on Weblogic 10.3.4 and it works fine. I created an application level workmanager, plugged it in your JobExecutor via the jndi ref, then created a process with an async service task and all is executed fine.

The thing i cannot judge though from your code is if there are any websphere specific semantics in it with regards to the way you schedule jobs for execution. Do you have an idea about this ?

thanks

[EDIT] it seems that there are some issues though, threads are getting stuck. Going to investigate and load test this.

Jorg Heymans

Bardioc
Offline
Last seen: 1 month 2 weeks ago
Joined: 09/06/2011 - 08:10
Posts: 31

heymjo wrote:
Hello Heiko,

I have tested your CommonJ interface code on Weblogic 10.3.4 and it works fine. I created an application level workmanager, plugged it in your JobExecutor via the jndi ref, then created a process with an async service task and all is executed fine.

The thing i cannot judge though from your code is if there are any websphere specific semantics in it with regards to the way you schedule jobs for execution. Do you have an idea about this ?

thanks

Hello,

actually not besides the usage of the UOWTransactionManager, which is Websphere specific, the code I wrote should work with all application servers that rely on WorkManagers. A caveat here is, that the WebSphereProcessConfiguration needs to extend the class SpringProcessConfiguration. That is necessary for the Transaction Manager to work correctly. However, if the API of Activiti would open the possibility to 'setJobExecutor()', which is currently not open API, one could simply remove the configuration object and provide a WorkManagerJobExecutor().

Great to hear, that this works for WebLogic too, so I will add another section to my upcoming chapter for Application Server support for the Activiti Documentation.

Thank you,

Heiko

heymjo
Offline
Last seen: 1 year 1 month ago
Joined: 02/01/2011 - 10:19
Posts: 143

I am seeing this in the weblogic console (the CommonJ is just a rename from the original Websphere* classes)

"[STUCK] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'" waiting for lock java.lang.Object@1eac46a TIMED_WAITING
 
java.lang.Object.wait(Native Method)          
org.activiti.engine.impl.jobexecutor.AcquireJobsRunnable.run(AcquireJobsRunnable.java:101)                    	   my.app.commonj.CommonJJobExecutor$JobAquisitionWork.run(CommonJJobExecutor.java:74)          
weblogic.work.j2ee.J2EEWorkManager$WorkWithListener.run(J2EEWorkManager.java:183)          
weblogic.work.ExecuteThread.execute(ExecuteThread.java:207)          
weblogic.work.ExecuteThread.run(ExecuteThread.java:176)

Looking around a bit this seems harmless though:

Quote:

In addition to reporting STUCK for requests that simply take a very long time, the stuck thread detector can mistakenly assume a thread is stuck if the thread is in a continuous loop doing real work -- for example servicing many requests in succession without ever returning to the thread pool.

Since this is exactly what the AcquireJobsRunnable is doing we can assume it is a non-event. A modest load test also did not reveal any problems, i'll report back in case anything appears.

Jorg Heymans

heymjo
Offline
Last seen: 1 year 1 month ago
Joined: 02/01/2011 - 10:19
Posts: 143

Hi,

Just a quick question still on this. IIUC the purpose of AcquireJobsRunnable, would this not be something that the commonj TimerManager could/should do ? The TimerManager schedules jobs (= classes implementing TimerListener) to run at a fixed interval in a 'managed' fashion.

      InitialContext ic = new InitialContext();
      TimerManager tm = (TimerManager)ic.lookup("java:comp/env/tm/default");
      // Execute timer every 10 seconds starting immediately
      tm.schedule (new MyTimerListener(), 0, 10*1000);

cheers

Jorg Heymans

sebastian.s
Offline
Last seen: 9 months 3 weeks ago
Joined: 05/17/2010 - 09:21
Posts: 71

Bringing this up again:

Since ACT-34 has been resolved what's the matter with adding activiti-websphere as an additional module? Maybe it should be generalized and renamed depending on the experiences Jorg made using it on WebLogic.

I could not find a JIRA issue for this topic. Please point me to the existing JIRA issue if existent. Otherwise I will create a new JIRA issue for this subject.

Sebastian
Some call it Europe - I call it home.

heymjo
Offline
Last seen: 1 year 1 month ago
Joined: 02/01/2011 - 10:19
Posts: 143

+1 for creating 'activiti-commonj' module

Jorg Heymans

melentye
Offline
Last seen: 6 months 2 weeks ago
Joined: 03/13/2013 - 08:56
Posts: 12

Hello all together

fyi: it is now possible not to extend EngineConfiguration anymore but instead inject a custom jobExecutor it using activiti.cfg.xml, I believe this is a result of ACT-34

    <bean id="processEngineConfiguration" class="org.activiti.cdi.CdiJtaProcessEngineConfiguration">
        <property name="transactionManager" ref="transactionManager" />
        <property name="dataSourceJndiName" value="XXX" />
        <property name="databaseSchemaUpdate" value="false" />
        <property name="databaseType" value="postgres" />
        <property name="jobExecutor" ref="commonjJobExecutor" />
        <property name="jobExecutorActivate" value="true" />
        <property name="transactionsExternallyManaged" value="true" />
    </bean>
 
    <bean id="commonjJobExecutor" class="org.activiti.commonj.CommonjJobExecutor">
        <property name="workManagerJndiName" value="java:comp/env/wm/ActivitiWM" />
    </bean>

Heiko, in the first reply you've mentioned that you have a version of JobAcquisitionThread implemented with TimerManager but it isn't in the attachment, would you mind sharing it with us?

The only issue I have seen under WL so far is the reports on stuck WorkManager threads (see heymro's comment) which are harmless and can be suppressed and the only stuck thread is actually JobAcqusitionThread running continuously in WorkManager

And of course another +1 for creating an activiti-commonj module for proper application server deployments.

regards,
Andrey