views:

61

answers:

4

If I start a Java app, it initiates and does some work then goes to thread sleep for an hour, then wake up after an hour and does some more work ...

But my PC is running Win7 and after 15 minutes of inactivity, it will go into sleep mode, so my question is : an hour from I started the Java app, if I don't touch the PC, and it goes into sleep mode, will my Java app still be able to wake up and do its work, and if so will the Win7 PC wake up with the screen turned on again [ because in Win7 sleep mode the screen turns off ] ?

+3  A: 

How could it possibly run if Windows isn't? There may be some tricks available with automatic wake-ups supported by the motherboard, but when the machine is in sleep mode, from the point of view of the OS and programs, it might as well be off.

EDIT: take note of the other answers which indicate work-arounds using some Windows APIs and tools (which presumably work with the motherboard to provide timed wake-ups).

siride
A: 

If your machine's asleep, then everything is suspended. Including any custom apps you might want to run.

Ben Poole
+4  A: 

A normal Thread.sleep() will not wake up the computer from sleep mode.

However, when registering a task with the Windows task scheduler, you can choose "wake the computer to run this task". When going to sleep mode, Windows will tell the motherboard the time of the next registered wake-up task.

Daniel
+1 Very interesting! Didn't know about that!
Will Marcouiller
+2  A: 

I know the client component of WHS allows your PC to wake itself to perform a client side backup. You can actually specify the option of waking the PC from sleep to perform the backup which is controlled via the actual WHS. How they accomplish this task is not via Java and I'm sure they have varying hooks into the OS, since in Sleep mode there is actually power still being supplied. Here is an article that talks about detecting the move to standby and preventing it, within Java/C++ and may hold value for what you are trying to accomplish in a different manner. In addition you could make use of WOL to wake the PC remotely.

Aaron