• 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

Timers

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 22789
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What error messages? Also, what kind of Timers are you using? javax.swing.Timer or java.util.Timer? TellTheDetails.
 
Mayur Gosalia
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22789
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok i will try changing the timers. would it make a difference if the interval for each timer was different?
 
Mayur Gosalia
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


what have i done wrong? becuase this will not execute in Java Eclipse, it starts and stops immediately without any output.
 
Rob Spoor
Sheriff
Posts: 22789
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.,
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic