Thread 'main' has priority of Thread.NORM_PRIORITY which is 5, you can check by inserting this line in the main(). System.out.println(Thread.currentThread().getPriority());
A sleeping thread could be interrupted while sleeping if other thread called interrupt() on the sleeping thread, from which it would become runnable again.
Joined: Nov 15, 2004
Thanks for your response Ahmed. Actually my 2nd question was different from your answer.
Joined: Apr 22, 2006
The time specified in sleep method is the minimum duration in which the thread won't run, but its not the exact duration in which the thread won't run.
When the thread executes its sleep method, immediately it goes from the running state to waiting/blocked state, and waits there until the time duration expires or if other thread invoked interrupt() on it.
However after that it enters the runnable state in which it has to stay in the runnable pool until it is selected to run again. So the exact time in which the thread won't run can't be determined.