0

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?

tarka
  • 5,289
  • 10
  • 51
  • 75
  • 1
    With EJBs it's recommended to use the Java EE [Timer Service](http://docs.oracle.com/javaee/6/tutorial/doc/bnboy.html) – perissf Dec 31 '12 at 13:40

1 Answers1

0

As per perissf comment:

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

tarka
  • 5,289
  • 10
  • 51
  • 75