• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

without giving notify control comes back to print main

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in the example given below , I have not given notify yet control comes back and prints main.I thought notify is necessary.

class B implements Runnable
{
public void run()
{
for(int i=0;i<10;i++)
{
System.out.println ("Number="+i);
}
}
}

public class H
{
public static void main(String[] args)
{
B b1=new B();
Thread t1=new Thread(b1);
t1.start();

synchronized(t1)
{
try
{
t1.wait();
}
catch(InterruptedException ex)
{
ex.printStackTrace();
}
System.out.println ("main");
}

}
}
 
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can check following post it may help you Explaination given by author Henry Wong

https://coderanch.com/t/234368/threads/java/wait-without-notify

Regards
Ninad
 
Something must be done about this. Let's start by reading this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic