• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Timer seems to not repeat

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was not aware that method existed! I will rewrite my code to utilize System.currentTimeMillis, thank you!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic