Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Creative commons Attribution-NonCommercial license. NO WARRANTY IS GIVEN OR IMPLIED, USE AT YOUR OWN RISK.
 package base.task;

Provides a mechanism to run a task at a regular interval without having to play with threads. When implementing a RegularTask you must ensure that the InterruptedException is respected to ensure the application server shutdown process is not broken.
public class RegularTaskHandler extends TaskHandler {
	private int interval = 1;

Initialise a regular task.

	public RegularTaskHandler(String taskNameTask taskint interval) {
		this. = interval;

Entry point to the handler. All work done by the handler is done within a loop, this allows tomcat to send a message to terminate the running of the thread. All work in the loop has a global Exception handler to prevent the thread terminating early.
	public void run() {
		try {
catch(InterruptedException ex) {}
		while(!) {
			try {
				sleep( * 1000);
catch(InterruptedException e) {
catch(Exception e) {
				try { sleep(3 * 1000); } catch (InterruptedException ex) {}
New to GrepCode? Check out our FAQ X