Since you are on Tomcat, which is just a barebones servletcontainer, you cannot use EJB @Schedulefor this, which is recommended by the Java EE specification. It is best to choose ScheduledExecutorServicefrom the Java 1.5 package java.util.concurrent. You can call this with ServletContextListener, as shown below:
@WebListener
public class BackgroundJobManager implements ServletContextListener {
private ScheduledExecutorService scheduler;
@Override
public void contextInitialized(ServletContextEvent event) {
scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(new SomeTask(), 0, 10, TimeUnit.MINUTES);
}
@Override
public void contextDestroyed(ServletContextEvent event) {
scheduler.shutdownNow();
}
}
where the class is SomeTaskas follows:
public class SomeTask implements Runnable {
@Override
public void run() {
}
}
Java EE EJB em (, Glassfish, JBoss AS, TomEE ..), @Singleton EJB @Schedule. , . , , EJB:
@Singleton
public class SomeTask {
@Schedule(hour="*", minute="*/10", second="0", persistent=false)
public void run() {
}
}
, , , (@PersistenceContext ..), ScheduledExecutorService — // , barebones servletcontainer, Tomcat.
, Timer "" - Java EE. , Java EE ( Java Concurrency ):
Timer , ScheduledExecutorService .Timer , . ScheduledExecutorService .- ,
TimerTask, , Timer , .. ( ). ScheduledThreadExecutor , , . , , , .