Inter-thread communication in Java
Carvia Tech | August 05, 2019 | 1 min read | 109 views
Inter-thread communication is all about allowing threads to communicate with each other over a shared mutable object.
Java’s Object class provides 3 final methods which allows inter-thread communication:
-
wait()
-
notify()
-
notifyAll()
All these methods must be used within a synchronized block only.
- wait()
-
It instructs the calling thread to give up the lock and go to sleep until some other thread enters the same monitor and calls notify()
- notify()
-
It wakes up a single thread that was in waiting state (because that thread called wait()) on the same object. Calling notify() does not actually give up a lock on a resource.
- notifyAll()
-
It functionality is quite similar to notify() except that it wakes up all the threads that were on waiting state on the same object.
Top articles in this category:
- Multi-threading Java Interview Questions for Investment Bank
- Citibank Java developer interview questions
- Morgan Stanley Java Interview Questions
- Sapient Global Market Java Interview Questions and Coding Exercise
- Java Concurrency Interview Questions
- UBS Java Interview Questions
- ION Trading Java Interview Questions
Find more on this topic:
Subscribe to Interview Questions
Recommended books for interview preparation:
Similar Posts
- Finastra Investment Banking Interview Questions
- Merge two sorted array into a single sorted array
- Spring Boot with GMAIL SMTP
- Mandrill emails in Spring Boot Java
- Hibernate & Spring Data JPA interview questions
- Generating cryptographically strong key/secret in Java
- Reverse the bits of a number and check if the number is palindrome or not
- MD5 and SHA256 in Java Kotlin and Android
- There is no PasswordEncoder mapped for the id
- Inter-thread communication in Java