如何在Servlet启动代码中使用J2EE Timer Service API? [英] How can I use the J2EE Timer Service API in the Servlet startup code?

查看:191
本文介绍了如何在Servlet启动代码中使用J2EE Timer Service API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我想在J2EE容器中运行的后台作业,我发现了创建启动servlet并使用Timer Service API创建托管Timer的建议(在 J2EE中定时批处理的工具是什么?。) p>

要创建计时器,我需要一个实现计时器API的上下文。 (示例



在Servlet类中,我重写了init方法,但它只能访问ServletContext,但不能访问SessionContext。 ServletContext没有创建计时器的方法,所以我被困在这里。



如何在servlet的启动代码中访问J2EE计时器服务?

解决方案

每当我听到计时器工作时,我都不禁认为这应该与Java EE应用服务器分开。您可以使用Quartz或操作系统计划任务,或者像AutoSys这样的批处理管理器,但是将它嵌入到servlet中似乎是对我的servlet滥用。



Java EE 5容器具有一个EJB的TimerService。也许将帮助您解决问题。


For a background job which I would like to run in a J2EE container, I found the suggestion to create a startup servlet and use the Timer Service API to create a managed Timer (in the answers for What tools are there for timed batch processes in J2EE?).

To create a timer, I need a context which implements the timer API. (Example)

In the Servlet class, I override the init method, but it has only access to a ServletContext, but not to a SessionContext. A ServletContext does not have methods to create timers, so I am stuck here.

How can I access the J2EE timer service in the startup code of a servlet?

解决方案

Whenever I hear timer job, I can't help but think that this should be separated from a Java EE app server. You can use something like Quartz, or an operating system scheduled task, or a batch manager like AutoSys, but embedding it into a servlet seems like a misuse of servlets to me.

Java EE 5 containers have a TimerService that's an EJB. Perhaps this will help you sort it out.

这篇关于如何在Servlet启动代码中使用J2EE Timer Service API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆