I have the following @Singleton bean that I am using to perform some scheduled tasks:
@Singleton
@Startup
public class SqsScheduler {
// Logger-------------------------------------------------------------------
private static final Logger LOG = Logger.getLogger(SqsScheduler.class.getName());
// Variables----------------------------------------------------------------
Timer timer;
StoredDynamoQueries storedDynamoQueries = new StoredDynamoQueries();
// Constructors-------------------------------------------------------------
public SqsScheduler() {
timer = new Timer();
timer.scheduleAtFixedRate(new ScheduledTask(), 0, 180 * 1000);
}
// Methods------------------------------------------------------------------
class ScheduledTask extends TimerTask {
@Override
public void run() {
// The scheduled tasks to perform
}
}
}
Everything works fine EXCEPT when I undeploy/redeploy the the application the TimerTasks don't get removed and the redeployed application then starts producing errors. If I undeploy the application, restart the server (Glassfish 3.1.2.2) and then deploy the application from scratch it works perfectly.
How would I go about removing the timers when the application is redeployed?