A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Java
»
Threads and Synchronization
Author
Example of wait and notify
Rahul Mahindrakar
Ranch Hand
Joined: Jul 28, 2000
Posts: 1831
posted
Aug 20, 2000 10:51:00
0
Here is a simple example of wait and notify
class thread1 { public static void main(String[] args) { x first =new x(); Thread new1=new Thread(first); Thread new2=new Thread(first); new1.start(); new2.start(); System.out.println("Hello World!"); } } class x implements Runnable { boolean x=true; public void run(){ while (true) { synchronized(this){ System.out.println("changing threads"); try { int i=0; for(i; i<10; i++){ System.out.println(i +" " + Thread.currentThread().getName()); } notify(); wait(); } catch (Exception e){ System.out.println("Error is " +e); } }//end of while }// end of run } }// end of class
Regds.
Rahul P. Mahindrakar.
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: Example of wait and notify
Similar Threads
interrupt
synchronize (this) - what does it mean?
Question about wait() and notify()
DudesChat clarification please?
Why cant i call main method from another class having main block
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter