Code:
public static void main(string args[])
{
for(int k=0;k<2;k++)
{
WorkerThread wk=new WorkerThread();
wk.start();
Thread.sleep(500); // who will sleep ? main thread or wk ?
who will sleep ? main thread or wk ?
Code:
sleep
public static void sleep(long millis)
throws InterruptedException
Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds. The thread does not lose ownership of any monitors.
after calling wk.start() what is the current executing thread ? i have read that even if you call start() method there is no gurantee that wk thread will be started. so, who will sleep ?