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 notifyAll(). Show all posts
Showing posts with label notifyAll(). Show all posts

Difference between notify and notifyAll in java

7:57 AM
notify(): When you call notify method on the object, it wakes one of thread waiting for that object. So if multiple threads are waiting for an object, it will wake of one of them. Now you must be wondering which one it will wake up. It actually depends on OS implementation. notifyAll() : notifyAll will wake up all threads waiting on that object unlike notify which wakes up only one of them.Which one will wake up first depends on thread priority and OS implementation. Lets understand it with the help of example: 1. Create a class named File.java: It is java bean class on which thread will act and call wait and notify method. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28   package org . arpit . java2blog . thread ;   public class File { String name ; boolean isCompleted ; public File ( String name ) { super ( ) ; this . name

.