Web 应用程序中的 Quartz

发布于 2024-08-28 16:32:01 字数 460 浏览 8 评论 0原文

我有一个关于在网络应用程序中安排作业的问题。如果我们必须在Web应用程序中调度作业,我们可以使用java util Timer/TimerTask或Quartz(还有其他调度机制,但我考虑了Quartz)。当我访问网站 http: 时,我正在考虑使用哪一个: //oreilly.com/pub/a/java/archive/quartz.html?page=1 其中表示使用计时器会产生不良影响,因为它会在最后一行创建一个不受容器控制的线程。其他页面讨论了 Quartz 及其功能,但我可以看到 Quartz 还使用线程和/或线程池来调度任务。我的猜测是这些线程也不在容器的控制之下

任何人都可以向我澄清这一点吗 在我的 Web 应用程序中使用 Quartz 是否安全,不会产生挂起线程或线程锁定问题? 提前致谢

I have a question in scheduling jobs in web application. If we have to schedule jobs in web application we can either use java util Timer/TimerTask or Quartz(there are also other scheduling mechanism, but I considered Quartz). I was considering which one to use, when i hit the site http://oreilly.com/pub/a/java/archive/quartz.html?page=1 which says using timer has a bad effect as it creates a thread that is out of containers control in the last line. The other pages discuss Quartz and its capabilities, but I can read that Quartz also uses thread and/or threadpool to schedule tasks. My guess is that these threads are also not under the containers control

Can anybody clarify this to me
Is it safe to use Quartz in my web applications without creating hanging threads or thread locking issues?
Thanks in advance

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

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

发布评论

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

评论(3

放赐 2024-09-04 16:32:01

任何人都可以向我澄清这一点吗?在我的 Web 应用程序中使用 Quartz 是否安全,不会产生挂起线程或线程锁定问题?

quartz 和 JDK Timer 都会启动无法访问 Java EE 上下文信息的非托管线程,这是最大的问题。 此外,它们可以在[应用程序服务器]不知情的情况下使用资源,在管理员无法控制其数量和资源使用情况的情况下存在,并妨碍应用程序服务器正常关闭或从故障中恢复资源的能力 (请参阅非托管线程)。

话虽如此,我没有遇到挂起的线程或锁定问题(我想这取决于你对它们所做的事情)。

如果这确实是一个问题,请考虑使用 JSR-237 Timer 和 WorkManager 实现(与托管线程一起使用),例如 Foo- CommonJ 而不是quartz 或JDK Timer。

Can anybody clarify this to me Is it safe to use Quartz in my web applications without creating hanging threads or thread locking issues?

Both quartz and the JDK Timer start unmanaged threads that do not have access to Java EE contextual information, that's the biggest issue. In addition, they can use resources without the [application server] knowing about it, exist without an administrator's ability to control their number and resource usage, and impede on the application server's ability to gracefully shutdown or recover resources from failure (see Unmanaged threads).

Having that said, I didn't face hanging threads or locking issues (I guess it depends on what you're doing with them though).

If really this is a concern, consider using a JSR-237 Timer and WorkManager implementation (that works with managed thread) like Foo-CommonJ instead of quartz or JDK Timer.

云雾 2024-09-04 16:32:01

两种方法都创建了非托管线程。我使用 Quartz 而不是 java Timer 进行调度,因为它提供了更大的灵活性(例如 cron 表达式)并且更易于管理。

Both approaches created unmanaged threads. I use Quartz for scheduling rather than java Timer since it offer more flexability (cron expressions, for example) and it better managable.

把人绕傻吧 2024-09-04 16:32:01

如果我必须用一句话来说,我会说使用 Quartz,因为它会为您管理与调度相关的低级工作。使用 Timer,您可以执行quartz 所做的所有操作(甚至使计时器线程不断轮询以检查 Web 应用程序是否正在运行并否则退出)。但这需要您在代码中完成。有了 Quartz,这一切就可以开箱即用。

现在详情
石英提供
1、工作坚持
2. 托管线程池,以便您创建适当数量的线程并让作业在此之后等待。
3. 初始化 servlet 以与您的 Web 应用程序集成。当应用程序关闭时,我认为它会关闭您的线程,但我还没有尝试过。所以我不会对此发表太多评论。
4. 基于RMI 的调度,适用于集群环境。

还有其他因素,但这些因素是人们更频繁使用石英的最大动力。

If I have to say in one line, I would say use Quartz as it will take care of managing scheduling related low level work for you. With Timer, you can do everything which quartz does (even make timer threads keep polling to check if web app is running and exit otherwise). But this needs to be done in your code by you. With Quartz all this you get out of the box.

Now details
Quartz provides
1. Job persistence
2. Managed thread pool so you create appropriate number of threads and make the jobs wait after that.
3. Initialization servlet to be integrated with your web application. When app shuts down, I think it takes care of closing your threads, but I have not tried it. So I would not comment much on it.
4. RMI based scheduling, for clustered environments.

There are others as well, but these ones have been the biggest motivators why people use quartz more frequently.

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