简体   繁体   English

在应用程序服务器中运行java“后台应用程序”

[英]Running a java “background application” in application server

My experience with application servers is limited to some basic servlet coding, so I am not even sure how to frame this question appropriately. 我对应用程序服务器的经验仅限于一些基本的servlet编码,所以我甚至不确定如何恰当地构建这个问题。

I need to write a java program that runs on the (java) application server and continuously executes a certain method (it will check for files in a certain directory). 我需要编写一个在(java)应用程序服务器上运行的java程序,并不断执行某个方法(它将检查某个目录中的文件)。

I have found a way to schedule the start of applications but need to know where to put the code that I would normally put in the main() method in a regular java program. 我找到了一种方法来安排应用程序的启动,但需要知道在常规java程序中将我通常放在main()方法中的代码放在何处。

没有直接回答您的问题,但请查看可能有用的Spring Batch

Take a look at the servlet event listeners. 看一下servlet事件监听器。

I think you should be able to hook into your code using a ServletContextListener . 我认为您应该能够使用ServletContextListener挂钩您的代码。

http://onjava.com/pub/a/onjava/2001/04/12/listeners.html http://onjava.com/pub/a/onjava/2001/04/12/listeners.html

You can use Quartz , or the EJB timer service (if you can learn EJBs) for this task. 您可以使用QuartzEJB计时器服务 (如果您可以学习EJB)来执行此任务。

If you have just a servlet container like Tomcat, it is preferable to go with Quartz. 如果您只有像Tomcat这样的servlet容器,那么最好使用Quartz。 In fact, Quartz also comes with a web application to monitor a scheduler . 实际上,Quartz还附带了一个用于监视调度程序Web应用程序

On the other hand, the EJB timer service is available in all EJB containers that support EJB 2.1 and above. 另一方面,EJB计时器服务在支持EJB 2.1及更高版本的所有EJB容器中都可用。

这样做的一种方法是编写一个实现ServletContextListener的Listener,然后编写您在contextInitialized方法中安排计时器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM