Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  This is free and unencumbered software released into the public domain.
  Anyone is free to copy, modify, publish, use, compile, sell, or
  distribute this software, either in source code form or as a compiled
  binary, for any purpose, commercial or non-commercial, and by any
  In jurisdictions that recognize copyright laws, the author or authors
 of this software dedicate any and all copyright interest in the
 software to the public domain. We make this dedication for the benefit
 of the public at large and to the detriment of our heirs and
 successors. We intend this dedication to be an overt act of
 relinquishment in perpetuity of all present and future rights to this
 software under copyright law.
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