Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Timer seems to not repeat  RSS feed

 
Derek Boring
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone!

So in my latest application, I have my main JFrame window and a background worker thread. When you click the 'Start' button on the main window, it starts the background worker thread and also sets a java.util.Timer using:



The timer's job is to increment a milliseconds variable to keep track of exactly how long the background thread takes to execute and also provide a time stamp relative to the start time for when the background thread prints to the log. The problem I am running into is the timer seems to not be calling the TimerTask (IncrementTime extends TimerTask) object's run method. If I set the delay parameter to 0, the run() method gets called once, but never again.

I create the timer object as a public field in my main window's (extending JFrame) class code using:


Here's all the possibly relevant code from the 'Start' button click event:

sendStopSignal(boolean stop) is a method I wrote into my AnalyzerProcess() class to gracefully and cleanly stop its current activity and then end the thread's execution.

The last thing the worker thread does before it finishes it's execution is call this method on the JFrame:


Here's my TimerTask extension class:

The System.out.println() never gets called.

This may be unnecessary, but just for completeness, here is my IncrementTime() method:


If you need any other info please let me know. Thank you so much in advance for your help! You guys here are all super awesome!
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I doubt a Timer will be able to keep track of milliseconds with great accuracy. Any particular reason you're not using System.currentTimeMillis?
 
Derek Boring
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was not aware that method existed! I will rewrite my code to utilize System.currentTimeMillis, thank you!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!