将 CommonJ 实现与 GlassFish 和 Spring 3 结合使用

发布于 2024-12-05 14:14:15 字数 3253 浏览 1 评论 0原文

在寻求统一 Websphere 7 和 GlassFish 3 环境之间的部署的过程中,我决定尝试在 GlassFish 中实现 CommonJ WorkManager 和 TimerManager。但它并没有完全按预期工作。我已完成以下操作:

使用位于以下位置的 myFOO CommonJ 实现: http://commonj.myfoo.de/并将库包含到我的 domain/lib 文件夹中(包括 Spring 库)

将以下内容添加到 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>

将引用包含在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>

完成所有这些设置后,所有内容都会加载并运行 Web 应用程序;但是,ThreadTester 类不在 Timer 上运行。

我已经单步执行了 myFOO 代码,并且 TimerManager (FooTimerManager.java) 主循环正在运行,它似乎从未认识到它应该每 30 秒启动该类。

我的问题:

有人有使用 GlassFish 3 和 Spring 实现 JSR 236/237 (CommonJ) 的经验吗?

除了 myFOO 之外,是否还有其他实现可供我使用和尝试? 有人尝试做我所做的事情吗?如果你成功了,你愿意分享你的成果吗?

谢谢!

编辑 1:

我忘了提及,就 WorkManager 而言,将 myFOO CommonJ 实现与 GlassFish 结合使用确实有效。 TimerManager不起作用。这意味着我可以按需启动线程,但触发调度不起作用。

编辑 2:

自从更新到 GlassFish 3.1.1 以来,TimerManager 的 myFOO CommonJ 实现工作正常。那么...太棒了!这个问题现在更像是一个 HOWTO 指南。

In my quest to unify deployment among Websphere 7 and GlassFish 3 environments, I decided to try implementing a CommonJ WorkManager and TimerManager in GlassFish. But it isn't quite working as expected. I have done the following:

Use the myFOO CommonJ implementation found at: http://commonj.myfoo.de/ and include the libraries into my domain/lib folder (including the Spring libs)

Added the following to the <resources> section of the 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>

Include the references in the <servers>/<server> section of the domain.xml:

  <resource-ref ref="wm/default"></resource-ref>
  <resource-ref ref="tm/default"></resource-ref>

Add the appropriate resource references in the web.xml of my test application:

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

Add the following beans to my 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>

After all of this set-up, everything loads find and the web application runs; however, the ThreadTester class does not run on the Timer.

I have stepped through the myFOO code and the TimerManager (FooTimerManager.java) main loop is running, it just never seems to recognize that every 30 seconds it's supposed to launch the class.

My questions:

Has anyone had experience implementing JSR 236/237 (CommonJ) with GlassFish 3 and Spring?

Is there another implementation somewhere other than myFOO that I could use and try out?
Has anyone attempted to do what I've done? Would you be willing to share your results if you succeeded?

Thanks!

Edit 1:

I forgot to mention that using myFOO CommonJ implementation with GlassFish does work as far as the WorkManager is concerned. What does not work is the TimerManager. This means that I can launch threads on demand just fine but triggered scheduling doesn't work.

Edit 2:

Since updating to GlassFish 3.1.1, the myFOO CommonJ implementation of the TimerManager is working fine. So... great! This question is now more like a HOWTO Guide.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夏天碎花小短裙 2024-12-12 14:14:15

我不认为使用 myFoo CommonJ 的 TimerManager 是一个好主意 - 除了休眠了大约 6 年之外,代码在某些地方还很奇怪(参考 v1.1)。例如,FooTimer 类的 isExpired 方法如下所示:

public boolean isExpired() {
    return scheduledExcecutionTime >= System.currentTimeMillis();
}

那么,当预定的下一次执行时间是在将来时,计时器将到期吗?胡说八道——这应该是相反的!

在其他地方 (TimerExecutor#run),notifyAll 在当前线程没有监视器的对象 (TimerManager) 上调用,不断导致 java.lang.IllegalMonitorStateExceptions。

把手拿开!

I don't think it's a good idea to use the TimerManager of myFoo CommonJ - in addition to being dormant for about 6 years, the code is just strange at some points (referring to v1.1). E.g. the isExpired method of the FooTimer class looks like this:

public boolean isExpired() {
    return scheduledExcecutionTime >= System.currentTimeMillis();
}

So, the timer will expire when its scheduled next execution time is in the future? Nonsense - that should be the other way round!

Somewhere else (TimerExecutor#run), notifyAll is called on an object (TimerManager) that the current thread has no monitor for, constantly causing java.lang.IllegalMonitorStateExceptions.

Hands off!

妞丶爷亲个 2024-12-12 14:14:15

如果您在 Spring 中工作,为什么要使用另一个 Timer 实现?为什么不直接使用 Spring 调度集成?那么你就不需要担心你的应用程序在哪个服务器上运行,因为 Spring 并不关心。

If you're working in Spring, why are you using another Timer implementation? Why not just use the Spring scheduling integration? Then you don't need to worry about in which server your app is running, as Spring doesn't care.

绾颜 2024-12-12 14:14:15

嗯,看起来自从更新到 GlassFish 3.1.1 以来,我不再遇到 TimerManager 的 myFOO 实现的问题。我的 @Scheduled beans 现在工作得很好。

Well, it looks like that since updating to GlassFish 3.1.1, I no longer have the problem with the myFOO implementation of the TimerManager. My @Scheduled beans are working just fine now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文