如何在 EJB 3 中创建同步计时器?
我在 EJB 3 中使用计时器。我需要完成以下要求。
例如:假设我创建了一个到期间隔为 10 分钟的计时器,初始计时器已启动,并且正在执行一些需要更多时间的任务(例如 15 分钟)。同时服务器将启动另一个同名定时器,并且已达到到期时间。如果现有计时器仍在运行,我想限制服务器启动另一个计时器。
另外,我想停止所有计时器,但是当我使用 timer.getInfo() 并获取计时器的名称时,应用程序会挂起。
请帮助解决这个问题。
I am using timers in EJB 3. I have the below requirements to accomplish.
Ex: Assume I have created a timer with expiry interval for 10mins, the initial timer started and it is performing some task which is taking more time (say 15mins). Meanwhile the server will start another timer with the same name and the expiry time has been reached. I want to restrict the server to start another timer if existing timer is still running.
Also I want to stop all timers but when I use timer.getInfo()
and get the name of timer, the application hangs.
Please help to resolve this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您创建的内容看起来像是一个间隔计时器/调度程序,它会在一定的时间间隔后继续执行,而不管之前的操作如何。
尝试手动创建计时器,在应用程序启动时在标记为 @Startup 的 bean 中创建它,可以进一步参考此处。
因此,一旦在应用程序启动时创建它,它将创建一个计时器链。因此,即使您的任务比平常花费更多时间,下一个任务也只会在前一个计时器完成/到期后才会创建。
What you have created seems like a interval-timer/scheduler which keeps executing after a certain interval, irrespective of previous actions.
Try creating the timer manually, create it in a bean marked as @Startup initializing with the application startup, can refer here further.
Therefore, once its created at the application startup, it will be creating a chain of timers. So even if your task takes more time than usual, the next will be created only after the completion/expiry of the previous timer.