使用集群在 JBoss 上调度任务

发布于 2024-08-17 07:27:32 字数 248 浏览 2 评论 0原文

我需要能够为在 JBoss 4.2 上运行的 EJB 应用程序运行一些计划任务(报告)。

在我的初始实现中,我在关联的 WAR 中使用 servlet 从属性文件中读取一些配置,然后使用计时器服务 API 重置计划任务。这可行,但在 Web 项目中关闭初始化似乎有点尴尬。另外,我不确定当应用程序部署在集群环境中时这是否会按预期工作。

完成此类任务的最佳实践是什么?我是否应该使用计时器服务以外的其他东西,是否有更好的方法在服务器启动时初始化计时器?

I need to be able to run some scheduled tasks (reports) for an EJB application running on JBoss 4.2.

In my initial implementation I am using a servlet in an associated WAR to read some configuration from a properties file and then reset the scheduled tasks using the Timer Service API. This works but it seems a bit awkward to have the initialization off in a web project. Also I'm not sure if this will work as expected when the app is deployed in a clustered environment.

What are the best practice for accomplishing this type of task? Should I be using something other than Timer Service and is there a better way to initialize the timers when the server starts?

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

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

发布评论

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

评论(1

征棹 2024-08-24 07:27:32

也许看看Quartz Scheduler。引用其网站:

Quartz 是一个功能齐全的开源作业调度系统,它可以与几乎任何 J2EE 或 J2SE 应用程序集成或一起使用 - 从最小的独立应用程序到最大的电子商务系统。 Quartz 可以用来创建简单或复杂的调度来执行数十、数百甚至数万个作业;其任务被定义为标准 Java 组件或 EJB 的作业。 Quartz Scheduler 包含许多企业级功能,例如 JTA 事务和集群。

我过去曾使用它来触发 EJB 作业,整个解决方案运行良好,具有非常好的可扩展性。要将其与 EJB 一起使用,您需要使用 JobStoreCMT存储调度信息(作业、触发器和日历)。要调整作业执行的资源,请查看配置线程池设置 文档。然后,如果 EJB 部署在集群上,则只需让 EJB 客户端完成其在不同实例上负载平衡请求的工作即可。

Quartz 本身也可以集群,以通过以下方式获得高可用性和可扩展性:如果需要,可以进行故障转移和负载平衡。

关于您提到的属性文件,我不确定您需要准确读取哪种数据,但是,如果没有 servlet,如果您需要读取某些内容,则必须从数据库中读取它。

Maybe have a look at Quartz Scheduler. Quoting its website:

Quartz is a full-featured, open source job scheduling system that can be integrated with, or used along side virtually any J2EE or J2SE application - from the smallest stand-alone application to the largest e-commerce system. Quartz can be used to create simple or complex schedules for executing tens, hundreds, or even tens-of-thousands of jobs; jobs whose tasks are defined as standard Java components or EJBs. The Quartz Scheduler includes many enterprise-class features, such as JTA transactions and clustering.

I've used it in the past to trigger EJB jobs and the whole solution was working very well, with very good scalability. To use it with EJB, you'll need to use the JobStoreCMT to store scheduling information (job, triggers and calendars). To tune resources for jobs execution, have a look at the Configure ThreadPool Settings doc. Then, just let the EJB client do its job to load balance requests over the different instances if EJBs are deployed on a cluster.

Quartz itself can also be clustered to get both high availability and scalability through fail-over and load balancing if required.

Regarding the properties file you mentioned, I'm not sure of what kind of data you need to read exactly but, without a servlet, if you need to read something, you'll have to read it from the database.

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