Recieving an exception while running workmanager task executor of spring in websphere. The following is my code
<bean id="workManager" class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor">
<property name="workManagerName" value="wm/MyWorkManager"/>
<property name="resourceRef" value="false"/>
</bean>
<bean name="myWorkManager" class="com.spring.test.services.concurrent.ConcurrentWorkManager" />
<bean name="myWorkListener" class="com.spring.test.services.concurrent.ConcurrentWorkListener" />
Code in my ConcurrentWorkManager
@Autowired
private WorkManagerTaskExecutor workManager;
@Autowired
private WorkListener myWorkListener;
if(workList==null){
throw new WorkException("There are no works present in worklist to do work");
}
ArrayList<WorkItem> workItems = new ArrayList<WorkItem>();
for(Work work : workList){
workItems.add(workManager.schedule(work,myWorkListener));
}
workManager.waitForAll(workItems,WorkManager.INDEFINITE);
for(WorkItem work:workItems){
ConcurrentWorker worker=(ConcurrentWorker)work.getResult();
resultString.add(worker.getResult());
}
Now when i am executing my code it is giving stackoverflow exception at workmanager.schedule(work) method
stackoverflow exception
at org.springframework.scheduling.commonj.WorkManagerTaskExecutor.schedule(WorkManagerTaskExecutor.java:202)
at org.springframework.scheduling.commonj.WorkManagerTaskExecutor.schedule(WorkManagerTaskExecutor.java:202)
at org.springframework.scheduling.commonj.WorkManagerTaskExecutor.schedule(WorkManagerTaskExecutor.java:202)
at org.springframework.scheduling.commonj.WorkManagerTaskExecutor.schedule(WorkManagerTaskExecutor.java:202)
at org.springframework.scheduling.commonj.WorkManagerTaskExecutor.schedule(WorkManagerTaskExecutor.java:202)
at org.springframework.scheduling.commonj.WorkManagerTaskExecutor.schedule(WorkManagerTaskExecutor.java:202)
at org.springframework.scheduling.commonj.WorkManagerTaskExecutor.schedule(WorkManagerTaskExecutor.java:202)
at org.springframework.scheduling.commonj.WorkManagerTaskExecutor.schedule(WorkManagerTaskExecutor.java:202)
at org.springframework.scheduling.commonj.WorkManagerTaskExecutor.schedule(WorkManagerTaskExecutor.java:202)
at org.springframework.scheduling.commonj.WorkManagerTaskExecutor.schedule(WorkManagerTaskExecutor.java:202)
at org.springframework.scheduling.commonj.WorkManagerTaskExecutor.schedule(WorkManagerTaskExecutor.java:202)
at org.springframework.scheduling.commonj.WorkManagerTaskExecutor.schedule(WorkManagerTaskExecutor.java:202)
at org.springframework.scheduling.commonj.WorkManagerTaskExecutor.schedule(WorkManagerTaskExecutor.java:202)
at org.springframework.scheduling.commonj.WorkManagerTaskExecutor.schedule(WorkManagerTaskExecutor.java:202)
at org.springframework.scheduling.commonj.WorkManagerTaskExecutor.schedule(WorkManagerTaskExecutor.java:202)
at org.springframework.scheduling.commonj.WorkManagerTaskExecutor.schedule(WorkManagerTaskExecutor.java:202)
When developing applications under WS-AS and you have to run threads, you should create and use a special WS internal resource called 'Work-Manager'.
This is the approach to run managed threads under IBM Websphere application server.
Adhere the following Stages to: first, define a work-manager resource on Websphere and after that, connect and use it in Spring:
Login into WS administrative console
Select: Resources -> Asynchronous beans -> Work managers.
Select a scope server+cell
Press the [new] button
define a Work-manager
also define your Work-manager JNDI name,
for example : wm/taskex11
In spring-config-file.xml add a as following:
<bean id="myTaskExecutor"
class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor">
<property name="workManagerName" value="wm/taskex11" />
</bean>
NOTE !
See the "workManagerName" property value.
The most important thing here, is to define the same Work-manager JNDI name you
specified in the Websphere admin console on stage 5 (above).
This is how Spring work-manager knows which WS JNDI it should locate
to exploit WS defined resource.
Seems this is the only way to run managed threads under IBM WS AS.
As you have this (stage-6) infra-bean defined in Spring, you can inject it into your
other application beans as you inject any other bean or resource:
@Autowired private WorkManagerTaskExecutor workManagerTaskExecutor;
Runnable r1 = new Runnable(){
@Override
public void run() {
for(int i = 0 ; i < 100;i++){
logger.info("run() method of Runnable. i=["+i+"], thread:["
+ Thread.currentThread().getName()+"]");
try {
Thread.sleep(500L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}//run
};//anonymous
workManagerTaskExecutor.execute(r1);
workManagerTaskExecutor.execute(r1);