• Post Reply Bookmark Topic Watch Topic
  • New Topic

wakeup at 5am  RSS feed

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

does anyone have any idea how to make sure that the application will wakeup exactly on a given hour, say 5am?

I know that Thread.Sleep(milliseconds) will wait for a while before exec but assuming I enter a value of 24 hours - that will be 24hr from the second i activate my program and not on a specific hour.

anyone?
 
Henry Wong
author
Sheriff
Posts: 22853
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the java.util.Timer class. One of the methods allows you to specified when to run a task based on a exact date and time, specified by the Date class.

Henry
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is a openSource API quarz (or quartz?)
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Henry,

thanks, i found somthing that might help me: http://www.javapractices.com/Topic54.cjp
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd use Timer, but let's talk a sec about what you could do if timer didn't exist. Get a date object for the time you want it to fire, get the milliseconds. Get the current milliseconds. Subtract now from target to get the difference in milliseconds and wait() that long. There's no deep magic there, but doing it yourself would be five or six steps of your own untested code compared to using Timer which is likely pretty good code, so stick with Timer unless you have a really good reason not to.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a job for the operating system. I would investigate what type of scheduling of tasks your particular OS has.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!