问题描述
在Websphere中运行spring的workmanager任务执行程序时收到异常.以下是我的代码
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" />
我的ConcurrentWorkManager中的代码
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());
}
现在,当我执行我的代码时,它在workmanager.schedule(work)方法中给出了stackoverflow异常
Now when i am executing my code it is giving stackoverflow exception at workmanager.schedule(work) method
stackoverflow异常
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)
推荐答案
如何在IBM Websphere(WS)应用程序服务器下设置和使用Spring WorkManagerTaskExecutor
(Yosi Lev撰写)
How to set and work with Spring WorkManagerTaskExecutor under IBM Websphere (WS) application server
(by Yosi Lev)
在WS-AS下开发应用程序时,必须运行线程,您应该创建并使用称为工作管理器"的特殊WS内部资源.这是在IBM Websphere应用程序服务器下运行托管线程的方法.
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.
遵循以下步骤:首先,在Websphere上定义工作管理器资源,然后在Spring中连接并使用它:
1.登录到WS管理控制台
2.选择:资源->异步bean->工作管理器.
3.选择作用域服务器+单元格
4.按下[新建]按钮
5.定义工作经理
还定义您的工作经理JNDI名称,
例如:wm/taskex11
6.在spring-config-file.xml中添加如下内容:
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>
注意!
请参阅"workManagerName"属性值.
这里最重要的是,定义与您
相同的Work-manager JNDI名称 在第5阶段(以上)的Websphere管理控制台中指定.
这就是Spring工作经理如何知道应该定位哪个WS JNDI的方式
利用WS定义的资源.
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.
似乎这是在IBM WS AS下运行托管线程的唯一方法.
7.在Spring中定义了这个(第6阶段)红外线之后,您可以将其注入到
注入任何其他bean或资源时,其他应用程序bean:
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.创建一个Runnable对象,并将其提供给workManagerTaskExecutor的execute()
方法:
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
这篇关于Websphere中的Spring Commonj.Workmanager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!