1

I need to create a persistent Java based application that will run at set intervals. If this was strictly running under Linux I could create a CRON job but it needs to run under Windows as well. Obviously I could use some sort of service wrapper but what about using a Servlet that simply never handles any GET/POST requests? The advantage in my mind is that both Windows and Linux has Servlet containers like Tomcat (At least in my environment). One code base that works in both environments and Tomcat itself will ensure that the application runs persistently like a service.

Is this a good use of a Servlet or am I straying outside of it's intended use?

gshauger
  • 714
  • 4
  • 16
  • You can use pycron on Windows: http://sourceforge.net/projects/pycron/ -- it operates like cron. – Jim Ferrans May 03 '11 at 05:01
  • Related: http://stackoverflow.com/questions/4691132/how-to-keep-the-servlet-continously-running – BalusC May 03 '11 at 11:17
  • Not related...I'm not asking how to keep a Servlet running persistantly. My question is whether they are useful when there is no HTTP request or response needed – gshauger May 03 '11 at 19:17

4 Answers4

3

No, don't use servlets. That's not what they were designed for.

What you want is Quartz. It's a library for executing scheduled jobs. It also includes classes for integrating the scheduler with a servlet environment - once you configure it, the scheduler starts when the application is loaded and stops when it's unloaded.

Mike Baranczak
  • 7,894
  • 6
  • 39
  • 65
2

The portability issue is solved almost automatically by using Java... I'd rather not use a servlet if there's no web interface.

Take a look to Quartz Scheduler framework which seems to be a perfect fit for your problem.

victor hugo
  • 34,018
  • 12
  • 65
  • 76
1

To problem of running Quartz as a service under Windows can be addressed by using one of the many possible service wrappers; e.g.

Stephen C
  • 632,615
  • 86
  • 730
  • 1,096
0

if your application not requires container- tomcat, jsp that just use Cron trigger in your application that runs it at interval

see this example

Nirmal- thInk beYond
  • 10,789
  • 8
  • 31
  • 44