Vivek Kamat
Vivek Kamat

Reputation: 307

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.

Upvotes: -1

Views: 93

Answers (2)

Basil Bourque
Basil Bourque

Reputation: 340230

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.

Upvotes: 0

Roman C
Roman C

Reputation: 1

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 * * * ?" />

Upvotes: 1

Related Questions