Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring commonj.Workmanager in websphere

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)
like image 975
Fryder Avatar asked Feb 21 '23 19:02

Fryder


1 Answers

How to set and work with Spring WorkManagerTaskExecutor under IBM Websphere (WS) application server

(by Yosi Lev)

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:
1. Login into WS administrative console
2. Select: Resources -> Asynchronous beans -> Work managers.
3. Select a scope server+cell
4. Press the [new] button
5. define a Work-manager
also define your Work-manager JNDI name,
for example : wm/taskex11
6. 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.
7. 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;


8. Create a Runnable object and provide it to the workManagerTaskExecutor's execute()
method:

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);


Good Luck,
Yosi Lev

like image 158
ylev Avatar answered Feb 26 '23 22:02

ylev