为了统一 Websphere 7 和 GlassFish 3 环境之间的部署,我决定尝试在 GlassFish 中实现 CommonJ WorkManager 和 TimerManager。但它并没有完全按预期工作。我做了以下事情:
使用位于以下位置的 myFOO CommonJ 实现:http://commonj.myfoo.de/ http://commonj.myfoo.de/并将库包含到我的domain/lib文件夹中(包括Spring库)
添加以下内容到<resources>
glassfish 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 类不在 Timer 上运行。
我已经单步执行了 myFOO 代码,并且 TimerManager (FooTimerManager.java) 主循环正在运行,它似乎从未认识到它应该每 30 秒启动该类。
我的问题:
有人有使用 GlassFish 3 和 Spring 实施 JSR 236/237 (CommonJ) 的经验吗?
除了 myFOO 之外,还有其他我可以使用和尝试的实现吗?
有人尝试做我所做的事情吗?如果你成功了,你愿意分享你的成果吗?
Thanks!
Edit 1:
我忘了提及将 myFOO CommonJ 实现与 GlassFish 结合使用does就 WorkManager 而言,工作。什么是not工作的是TimerManager。这意味着我可以按需启动线程,但触发调度不起作用。
Edit 2:
自从更新到 GlassFish 3.1.1 以来,TimerManager 的 myFOO CommonJ 实现工作正常。很好!这个问题现在更像是一个 HOWTO 指南。