eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Summer Sale 2026 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

Course – Summer Sale 2026 – NPI (cat=Baeldung)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

1. Overview

In this article, we’ll go over a Java thread state — specifically, Thread.State.WAITING. We’ll look at the methods with which a thread enters this state and the differences between them. Finally, we’ll take a closer look at the LockSupport class, which offers several static utility methods for synchronization.

2. Entering Thread.State.WAITING

Java provides multiple ways to put a thread in the WAITING state.

2.1. Object.wait()

One of the most standard ways we can put a thread in the WAITING state is through the wait() method. When a thread owns an object’s monitor, we can pause its execution until another thread has completed some work and wakes it up using the notify() method. While execution is paused, the thread is in the WAITING (on object monitor) state, which is also reported in the program’s thread dump:

"WAITING-THREAD" #11 prio=5 os_prio=0 tid=0x000000001d6ff800 nid=0x544 in Object.wait() [0x000000001de4f000]
   java.lang.Thread.State: WAITING (on object monitor)

2.2. Thread.join()

Another method we can use to pause a thread’s execution is through the join() call. When our main thread needs to wait for a worker thread to finish first, we can call join() on the worker thread instance from the main thread. Execution will be paused and the main thread will enter the WAITING state, reported from jstack as WAITING (on object monitor):

"MAIN-THREAD" #12 prio=5 os_prio=0 tid=0x000000001da4f000 nid=0x25f4 in Object.wait() [0x000000001e28e000]
   java.lang.Thread.State: WAITING (on object monitor)

2.3. LockSupport.park()

Finally, we can also set a thread to the WAITING state with the park() static method of the LockSupport class. Calling park() will stop execution for the current thread and put it into the WAITING state — and more specifically, the WAITING (parking) state as the jstack report will show:

"PARKED-THREAD" #11 prio=5 os_prio=0 tid=0x000000001e226800 nid=0x43cc waiting on condition [0x000000001e95f000]
   java.lang.Thread.State: WAITING (parking)

Since we want to better understand thread parking and unparking, let’s take a closer look at how this works.

3. Parking and Unparking Threads

As we previously saw, we can park and unpark threads by using the facilities provided by the LockSupport class. This class is a wrapper of the Unsafe class, and most of its methods immediately delegate to it. However, since Unsafe is considered an internal Java API and shouldn’t be used, LockSupport is the official way we can get access to the parking utilities.

3.1. How to Use LockSupport

Using LockSupport is straightforward. If we want to stop a thread’s execution, we call the park() method. We don’t have to provide a reference to the thread object itself — the code stops the thread that calls it.

Let’s look at a simple parking example:

public class Application {
    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            int acc = 0;
            for (int i = 1; i <= 100; i++) {
                acc += i;
            }
            System.out.println("Work finished");
            LockSupport.park();
            System.out.println(acc);
        });
        t.setName("PARK-THREAD");
        t.start();
    }
}

We created a minimal console application that accumulates the numbers from 1 to 100 and prints them out. If we run it, we’ll see that it prints Work finished but not the result. This is, of course, because we call park() right before.

To let the PARK-THREAD finish, we must unpark it. To do this, we have to use a different thread. We can use the main thread (the thread running the main() method) or create a new one.

For simplicity, let’s use the main thread:

t.setName("PARK-THREAD");
t.start();

Thread.sleep(1000);
LockSupport.unpark(t);

We add a one-second sleep in the main thread to let the PARK-THREAD finish the accumulation and park itself. After that, we unpark it by calling unpark(Thread). As expected, during unparking, we must provide a reference to the thread object that we want to start.

With our changes, the program now properly terminates and prints the result, 5050.

3.2. Unpark Permits

The internals of the parking API work by using a permit. This, in practice, works like a single permit Semaphore. The park permit is used internally to manage the thread’s state with the park() method consuming it, while unpark() makes it available.

Since we can only have one permit available per thread, calling the unpark() method multiple times has no effect. A single park() call will disable the thread.

What is interesting, however, is that the parked thread waits for a permit to become available to enable itself again. If a permit is already available when calling park(), then the thread is never disabled. The permit is consumed, the park() call returns immediately, and the thread continues execution.

We can see this effect by removing the call to sleep() in the previous code snippet:

//Thread.sleep(1000);
LockSupport.unpark(t);

If we run our program again, we’ll see that there’s no delay in the PARK-THREAD execution. This is because we call unpark() immediately, which makes the permit available for park().

3.3. Park Overloads

The LockSupport class contains the park(Object blocker) overload method. The blocker argument is the synchronization object that is responsible for thread parking. The object we provide doesn’t affect that parking process, but it’s reported in the thread dump, which could help us diagnose concurrency issues.

Let’s change our code to contain a synchronizer object:

Object syncObj = new Object();
LockSupport.park(syncObj);

If we remove the call to unpark() and run the application again, it will hang. If we use jstack to see what the PARK-THREAD is doing, we’ll get:

"PARK-THREAD" #11 prio=5 os_prio=0 tid=0x000000001e401000 nid=0xfb0 waiting on condition [0x000000001eb4f000]
   java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x000000076b4a8690> (a java.lang.Object)

As we can see, the last line contains which object the PARK-THREAD is waiting for. This is helpful for debugging purposes, which is why we should prefer the park(Object) overload.

4. Parking vs. Waiting

Since both of these APIs give us similar functionality, which should we prefer? In general, the LockSupport class and its facilities are considered low-level API. Additionally, the API can be easily misused, leading to obscure deadlocks. For most cases, we should use the Thread class’s wait() and join().

The benefit of using parking is that we don’t need to enter a synchronized block to disable the thread. This is important because synchronized blocks establish a happens-before relationship in the code, which forces a refresh of all the variables and can potentially lower performance if it’s not needed. This optimization, however, should rarely come into play.

5. Conclusion

In this article, we explored the LockSupport class and its parking API. We looked at how we can use it to disable threads and explained how it works, internally. Finally, we compared it to the more common wait()/join() API and showcased their differences.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Summer Sale 2026 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

Course – Summer Sale 2026 – NPI (All)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

eBook – Java Concurrency – NPI (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook Jackson – NPI EA – 3 (cat = Jackson)