Continuous Test Orchestration And Execution Platform Online

Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.

How to use wait() in Java?

The wait() method is part of the java.lang.Object class, which means that any thread can call it. When you call wait(), your thread stops its execution until another thread invokes notify() or notifyAll().

When a thread calls the wait method on an object, it releases ownership of the object's monitor. After this, another thread can call the notify method on that object to wake up one or all of the threads waiting for it. A thread that wakes up returns control to the point where it waits.

Java's synchronized methods and blocks allow a program to control, which threads can acquire the lock on a resource at any given time. When wait() is called by a thread, it gives up the lock on that resource and goes to sleep, waiting for some other thread to invoke notify() or notifyAll().

The easiest way to make a Java program wait is by using the Thread. sleep() method. The sleep() method is present in the Thread class and pauses the current thread for a specific time.

LambdaTest

Test your websites, web-apps, or mobile apps seamlessly with LambdaTest.

Start Free Testing
LambdaTest

Earn resume-worthy Selenium certifications that help you land a top job.

Learn More
LambdaTest

Test your web or mobile apps

Test orchestration and execution cloud of 3000+ browsers and OS

Support

24/7 support

Security

Enterprise grade security

Cloud

Fastest test execution cloud