0
votes

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?

1
With EJBs it's recommended to use the Java EE Timer Service - perissf
Thanks perissf, that fixed it. - tarka

1 Answers

0
votes

As per perissf comment:

With EJBs it's recommended to use the Java EE Timer Service