wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Timers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Timers" Watch "Timers" New topic
Author

Timers

Mayur Gosalia
Ranch Hand

Joined: Jan 03, 2010
Posts: 54
Hi,

I have used two timers in my system but since i have implemented this two timers, i am getting random error messages thrown from any part of the systemn this didnt happen before the timer were implemented. So i suspecting that at some point both timers are interfering with eachother and therefore causing this problems.

Is there anyway in Java to control the two timers? i.e. dont sttart the other timer until one timer is finished? or any other ideas that might stop this problem.

Thank You
Maz
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

What error messages? Also, what kind of Timers are you using? javax.swing.Timer or java.util.Timer? TellTheDetails.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mayur Gosalia
Ranch Hand

Joined: Jan 03, 2010
Posts: 54
Well the error messages are the ones that i have defined within the system. For example whilst its trying to reload the data sometimes it throws No Data Found error.
I am using the java.util.Timer.

If i disable the timers, these messages disappear but it doesnt happen always only sometimes.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

I think you are getting a synchronization problem. Read concurrency in Swing. I think that if you switch to a javax.swing.Timer you will work around the synchronization problem.
Mayur Gosalia
Ranch Hand

Joined: Jan 03, 2010
Posts: 54
ok i will try changing the timers. would it make a difference if the interval for each timer was different?
Mayur Gosalia
Ranch Hand

Joined: Jan 03, 2010
Posts: 54


what have i done wrong? becuase this will not execute in Java Eclipse, it starts and stops immediately without any output.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Swing timers are daemon threads - they will not prevent the application from shutting down. If you run them inside your full application with its main window it will work.
Mayur Gosalia
Ranch Hand

Joined: Jan 03, 2010
Posts: 54
so there is nothing wrong with this code? I simply have to put my actual code in the action listener and it will work?

I was just trying this as a simple test and because it didnt work i was wondering if i did something wrong.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Mayur Gosalia wrote:so there is nothing wrong with this code? I simply have to put my actual code in the action listener and it will work?

I was just trying this as a simple test and because it didnt work i was wondering if i did something wrong.


There's nothing wrong with it other than what was mentioned above.

To keep it alive:


edit: but a better example is to use a Swing Timer with Swing objects. For e.g.,
 
wood burning stoves
 
subject: Timers