为了在Websphere 7和GlassFish 3环境中统一部署,我决定尝试在GlassFish中实现CommonJ WorkManager和TimerManager。但它并没有像预期的那样起作用。我做了以下工作:
使用在: myFOO中找到的CommonJ实现,并将库包含到我的域/lib文件夹中(包括Spring )
将以下内容添加到glassfish domain.xml的domain.xml部分:
<custom-resource res-type="commonj.work.WorkManager" jndi-name="wm/default" factory-class="de.myfoo.commonj.work.FooWorkManagerFactory"></custom-resource>
<custom-resource res-type="commonj.timers.TimerManager" jndi-name="tm/default" factory-class="de.myfoo.commonj.timers.FooTimerManagerFactory"></custom-resource>将引用包含在<servers>/<server>节的domain.xml中:
<resource-ref ref="wm/default"></resource-ref>
<resource-ref ref="tm/default"></resource-ref>在测试应用程序的web.xml中添加适当的资源引用:
<resource-ref>
<description>WorkManager</description>
<res-ref-name>wm/default</res-ref-name>
<res-type>commonj.work.WorkManager</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-ref>
<description>TimerManager</description>
<res-ref-name>tm/default</res-ref-name>
<res-type>commonj.timers.TimerManager</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Unshareable</res-sharing-scope>
</resource-ref>将以下bean添加到我的applicationContext.xml中:
<bean id="threadTestTaskExecutor" class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor">
<property name="workManagerName" value="wm/default" />
<property name="resourceRef" value="true"/>
</bean>
<bean id="threadTestTimerExecutor" class="org.springframework.scheduling.commonj.TimerManagerTaskScheduler">
<property name="timerManagerName" value="tm/default" />
<property name="resourceRef" value="true" />
<property name="shared" value="false" />
</bean>
<bean id="threadTest" class="test.ThreadTester"></bean>
<task:scheduled-tasks scheduler="threadTestTimerExecutor">
<task:scheduled ref="threadTest" method="execute" fixed-delay="30000" /> <!-- 30 seconds -->
</task:scheduled-tasks>在进行了所有这些设置之后,所有的内容都会加载find,web应用程序就会运行;但是,ThreadTester类不会在计时器上运行。
我已经完成了myFOO代码,TimerManager (FooTimerManager.java)主循环正在运行,它似乎从来没有意识到它应该每30秒启动一个类。
我的问题:
是否有使用GlassFish 3和Spring?实现JSR 236/237 (CommonJ)的经验?
除了myFOO之外,还有其他可以使用和试用的实现吗?有人想做我做过的事吗?如果你成功了,你愿意分享你的成果吗?
谢谢!
编辑1:
我忘记提到使用myFOO CommonJ实现和GlassFish 一起做对于WorkManager来说是可行的。而不是工作的是TimerManager。这意味着我可以按需启动线程,但触发的调度不起作用。
编辑2:
自更新到GlassFish 3.1.1以来,TimerManager的myFOO CommonJ实现运行良好。所以..。太棒了!这个问题现在更像是一个指南。
发布于 2012-03-22 21:57:04
看来,自从更新到GlassFish 3.1.1之后,myFOO TimerManager实现就不再有问题了。我的@Scheduled bean现在运行得很好。
发布于 2012-06-15 14:24:11
我不认为使用TimerManager of myFoo CommonJ是个好主意--除了休眠大约6年之外,代码在某些地方(参考v1.1)很奇怪。例如,isExpired类的FooTimer方法如下所示:
public boolean isExpired() {
return scheduledExcecutionTime >= System.currentTimeMillis();
}那么,计时器将在其预定的下一个执行时间在未来到期?胡说八道-那应该是另一回事!
在其他地方(TimerExecutor#run),在当前线程没有监视器的对象(TimerManager)上调用notifyAll,这会经常导致java.lang.IllegalMonitorStateExceptions。
把手拿开!
发布于 2011-09-20 23:12:26
如果您在Spring工作,为什么要使用另一个计时器实现?为什么不直接使用弹簧调度集成呢?那么你就不需要担心你的应用程序在哪个服务器上运行了,因为Spring并不在意。
https://stackoverflow.com/questions/7490297
复制相似问题