(URGENT) How can a Thread automatically start only once at 7.00pm(specific time) everyday?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   stanley_ten
Posted On:   Wednesday, November 28, 2001 05:55 PM

How can a Thread automatically start only once at 7.00 pm everyday? It's helpfull if anyone can give some code example... thanks...

Re: (URGENT) How can a Thread automatically start only once at 7.00pm(specific time) everyday?

Posted By:   Alex_Chaffee  
Posted On:   Thursday, November 29, 2001 09:10 AM

If it's so urgent, why didn't you search the FAQ? You could have easily found How do I schedule a task to run at a certain time?


The "Search" box is there for a reason... use it and be happy.

Re: (URGENT) How can a Thread automatically start only once at 7.00pm(specific time) everyday?

Posted By:   Fred_Gracely  
Posted On:   Thursday, November 29, 2001 07:25 AM

Using java.util.Timer, you can specify that a TimerTask object be executed at a specific time. Here is a code snippet:



//Get the Date corresponding to 11:01:00 pm today.
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 1);
calendar.set(Calendar.SECOND, 0);
Date time = calendar.getTime();

timer = new Timer();
timer.schedule(new [TimerTask Class Name], time);


To establish repeated execution, you should probably use one of the
scheduleAtFixedRate Timer methods.


More information is available at:


http://java.sun.com/docs/books/tutorial/essential/threads/timer.html

Hope this helps.

About | Sitemap | Contact