Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run periodic tasks on server in the background

What's the best/easiest way to run periodic tasks (like a daemon thread) on a tomcat/jetty server? How do I start the thread? Is there a simple mechanism or is this a bad idea at all?

like image 706
Harald Schilly Avatar asked Dec 08 '22 08:12

Harald Schilly


2 Answers

If want to keep everything on java side, give a look to Quartz.
It handles failover and fine grained repartition of jobs, with the same flexibility of cron jobs.

like image 164
MatthieuP Avatar answered Dec 09 '22 21:12

MatthieuP


It's okay and effective to stash a java.util.Timer (or better yet ScheduledExecutor) instance in your ServeletContext. Create it in a Servlet's init() call and all your servlets can add TimerTasks to it.

like image 44
Ry4an Brase Avatar answered Dec 09 '22 21:12

Ry4an Brase