3

I go to the FTP each 2 mins to upload new files. I implemented it with java.util.Timer. But after some time - several days or even week - it stops without any exception and without any reason.

I found thread: Java unlimited thread stops after some time

But there is no particular solution in it. I read about ScheduledExecutorService, but as far as I understand - it's the same as Timer.

Please give me some ideas!

Community
  • 1
  • 1
Elena
  • 145
  • 3
  • 13
  • 1
    Timers run on a sparate thread. if any exception occurs, the thread stops. catch all throwables in run() or similar method, and output it to log. – AlexWien Feb 01 '13 at 12:42

2 Answers2

0

You can try to set a default Exception handler using Thread.setDefaultUncaughtExceptionHandler() API in your main thread and try to log any throwable/exception that could get swallowed silently.

Bimalesh Jha
  • 1,402
  • 9
  • 13
0

I just saw that no one have answered this question, maybe because this is a duplicate.

ScheduledExecutorService uses System.nanotime() and Java.util.Timer uses System.currentTimeMillis().

System.currentTimeMillis() depends up on system time and System.nanotime() gives nanoseconds since some fixed arbitrary initial time and is not related to system time. So any change in system time (due to NTP time correction or system stand-by) may or may not impact Timer execution. This would be the reason that your timer fails.

For more details please refer - What should Timertask.scheduleAtFixedRate do if the clock changes?

Community
  • 1
  • 1
Zac
  • 143
  • 1
  • 8