Java-Inter Thread Communication (Another Example)

Program Program Source class Data { boolean condition = false; synchronized void print_1_to_5() { condition = true; try{ for(int i=1;i<=5;i++) { Thread.sleep(1000); System.out.println(“Print_1_to_5 : “+i); } }catch(InterruptedException ie) { System.out.println(“Child Thread Interrupted”); } notify(); } synchronized void print_6_to_10() { if(!condition) { try{ System.out.println(“First thread called Print_6_to_10 method”); System.out.println(“So its waiting to second thread complete”); wait(); … Read more…

Java-Inter Thread Communication

Inter thread communication Inter-thread communication can be defined as the exchange of messages between two or more threads. The transfer of messages takes place before or after the change of state of a thread. For example, an active thread may notify to another suspended thread just before switching to the suspend state. The wait( ), … Read more…