JavaGian java tutorial and java interview question and answer

JavaGian , Free Online Tutorials, JavaGian provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, ajax, core java, sql, python, php, c language etc. for beginners and professionals.

Showing posts with label java inter thread communication. Show all posts
Showing posts with label java inter thread communication. Show all posts

java inter thread communication

10:05 PM
If you are aware of interprocess communication then it will be easy for you to understand interthread communication. Interthread communication is important when you develop an application where two or more threads exchange some information. There are three simple methods and a little trick which makes thread communication possible. All the three methods are listed below − Sr.No. Method & Description 1 public void wait() Causes the current thread to wait until another thread invokes the notify(). 2 public void notify() Wakes up a single thread that is waiting on this object's monitor. 3 public void notifyAll() Wakes up all the threads that called wait( ) on the same object. These methods have been implemented as  final  methods in Object, so they are available in all the classes. All three methods can be called only from within a  synchronized  context. Example This examples shows how two threads can communicate using  wait() ...

.