Reputation: 81
My experience with application servers is limited to some basic servlet coding, so I am not even sure how to frame this question appropriately.
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).
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.
Upvotes: 3
Views: 2123
Reputation:
One way of doing this is to write a Listener which implements ServletContextListener and you write you schedule your timer in contextInitialized method
Upvotes: 0
Reputation: 11779
Not answering straight to your question, but check out Spring Batch that could be useful.
Upvotes: 2
Reputation: 76709
You can use Quartz, or the EJB timer service (if you can learn EJBs) for this task.
If you have just a servlet container like Tomcat, it is preferable to go with Quartz. In fact, Quartz also comes with a web application to monitor a scheduler.
On the other hand, the EJB timer service is available in all EJB containers that support EJB 2.1 and above.
Upvotes: 1
Reputation: 17629
Take a look at the servlet event listeners.
I think you should be able to hook into your code using a ServletContextListener
.
http://onjava.com/pub/a/onjava/2001/04/12/listeners.html
Upvotes: 1