This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Timer Threads in JDK1.2  RSS feed

 
Vijay S. Rathore
Ranch Hand
Posts: 449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to create timer threads using JDK1.2?

Swing is not an option in my application.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure. There's nothing magic about java.util.Timer nor javax.swing.Timer -- they each just use a Thread which invokes a method on a class (a Runnable or an ActionListener) that you supply. They both use Thread.sleep() to wait for a specified time before invoking the method, and the Swing version uses invokeAndWait() to force the method call onto the event thread.

In any case, neither of these classes is very complex, and you could easily write your own.
 
Vijay S. Rathore
Ranch Hand
Posts: 449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I could not see java.util.Timer or java.util.TimerTask in JDK1.2. Or am I mistaken?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I'm saying is that you could easily write your own versions of these classes that you could then use in JDK 1.2. They're simple and contain no native code or other magic.
 
Vijay S. Rathore
Ranch Hand
Posts: 449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ernest Friedman-Hil for suggestion. It worked for me.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!