What is the difference between wait() and sleep() in Java?
Ask by Ashutosh Patel
Updated 19 Jul 2024
Difference between wait() and sleep()
Both
wait()andsleep()methods are used in Java for concurrent scheduling, but serve different purposes:wait()
Example-
sleep()
Example-
Specifically,
wait()is used for communication between threads in synchronous context, whilesleep()is used to pause execution for a specified period of time, regardless of sessionAlso, Read: What are the key features introduced in Java 8?