0

I have a JavaEE application deployed to Weblogic 10.3. In my application, I created a Timer and TimerTask that started at the beginning of the application loading up by doing the following:

TimerTask t = new TimerTask() {
    @Override
    public void run() {
        // Perform task
    }
};
Timer timer = new Timer();
timer.scheduleAtFixedRate(t, 0, 15000);

The problem is, after redeploying the application, the previous timer tasks are still executing. So after 5 deployments, there are 5 timers executing. I don't have the ability to restart the Weblogic server, and I've searched around for a solution but to no avail. Is there any way to stop these tasks?

I no longer need to use the TimerTask, I would just like to stop the ones that are still currently executing.

blacktide
  • 7,668
  • 6
  • 25
  • 45
  • This is a [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). Using `Timer` in Java EE is in first place already wrong at its own. Is this acceptable as dupe? http://stackoverflow.com/q/4691132 – BalusC Aug 03 '15 at 13:48
  • Based on this answer: http://stackoverflow.com/questions/8983334/how-to-make-ejb-timer-persistent-to-false i would use '@Schedule' which has the persistent property – maress Aug 03 '15 at 13:50
  • This isn't an XY problem. I no longer need to use the TimerTask. My question is how can I stop the tasks currently running, not how can I keep them from persisting. I will edit to clarify this. – blacktide Aug 03 '15 at 13:57
  • I dont know where weblogic stores its times, but you can find out from weblogic documentation. In wildfly i normally have a folder in the deployment content of the application named ejb-timer-services, where i can manually delete the times. – maress Aug 03 '15 at 14:02
  • You can't. Those threads are not managed by the server due to the severe design mistake of using `Timer` in Java EE as pointed out in that duplicate. Only solution is to restart the server. – BalusC Aug 03 '15 at 14:33
  • @BalusC, Thank you very much for the information. – blacktide Aug 03 '15 at 16:35

1 Answers1

0

As BalusC points out here, it is not possible to cancel the TimerTasks. The threads are not managed by the server, so the only solution is to restart the server.

Community
  • 1
  • 1
blacktide
  • 7,668
  • 6
  • 25
  • 45