Timer for Java

I would like to have a timer in my Java Applet that polls a website every prescribed time. Is there a property or code that I could use?
BarkleyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JodCommented:
The easiest way to do this is to set up the process that is doing the polling to go to sleep and then wake up every specified interval and poll the site.

Even better, put this code into a separate thread to keep it out of the way.

You can do it like this:

while (true) {
  try {
    thread.sleep(1000 * secs);
  } catch {InterruptedException e) {)
  //poll the website and process data
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bhatdCommented:
Using Timers to poll every second

Timer timer = new Timer( 1000, new ActionListener
{
public void actionPerformed( ActionEvent e )
   {
    //poll server
   }
 }
);
timer.setRepeats( true );
timer.start();
0
BarkleyAuthor Commented:
How do I create a separate thread?Because when I do the sleep, I cannot click any other buttons while the application  is running.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.