简体   繁体   中英

How to call Java method on patricular interval of time which is deployed to Apache Tomcat server as a web application?

I'm developing an web application which is developed in Struts 2 and I'm deploying it on Apache Tomcat server.

I want to do database cleanup on daily basis automatically.

Also I want to to call a method in java class with 10 minutes of interval. Any suggestion for this.

You can use Quartz scheduler with Struts2 or Spring's @Scheduled . Here's the example to use Struts 2 + Spring 3 + Quartz 1.8 Scheduler Example .

There you can modify cron expression to run every 10 min

<property name="cronExpression" value="* 0/10 * * * ?" />

ScheduledExecutorService

This topic has been addressed many times already on a Stack Overflow.

Learn about executors .

Specifically look at ScheduledExecutorService .

A background thread can run your task at regular intervals.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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