Pages

Topics

Tools

↑↓navigate↵openescclose

Java guides

Every published Java guide, newest first, with practical examples you can copy into your own project.

3,965 guides across 14 topics

Topics

Latest Java guides

Diagram showing Java thread state transitions from NEW to TERMINATED with monitoring tools.
Java

Java Thread States: Lifecycle and Monitoring

Understand the six Java thread states, how threads transition between them, and how to observe states with getState(), thread dumps, and monitoring tools.

ThreadsConcurrencyThread LifecycleThread Dump
Diagram showing the six states of a Java thread lifecycle with arrows for transitions between states.
Java

Java Thread Lifecycle: States and Transitions

Understand the six Java thread states, how threads transition between them, and how to monitor and manage thread lifecycle in production.

Thread StatesConcurrencyMultithreadingThread Management
A thread being interrupted with a flag, representing Java's cooperative cancellation mechanism.
Java

Java Thread Interrupt: How It Works and How to Use It

Learn how the Java thread interrupt mechanism works, how to handle InterruptedException, and how to use interrupt flags for cooperative cancellation in real applications.

threadingconcurrencyinterruptmultithreading
Illustration of a main thread waiting for a worker thread to complete using Thread.join()
Java

Java Thread Join: Waiting for Threads to Finish

java thread join: Learn how Thread.join() blocks the calling thread until a worker finishes, including timeout variants, interrupt handling, and common pitfalls.

Thread.joinJava concurrencymultithreadingthread synchronization
Illustration of a Java thread pausing with a clock and interruption signal, representing Thread.sleep behavior.
Java

Java Thread.sleep: Usage, Pitfalls, and Alternatives

Understand how Thread.sleep works in Java, handle InterruptedException correctly, avoid common pitfalls, and learn better alternatives for concurrency.

Thread.sleepConcurrencyInterruptedExceptionJava Concurrency
Diagram showing Thread.start() creating a new thread versus Thread.run() executing in the main thread
Java

Java start vs run: Thread Behavior Explained

Understand the difference between Thread.start() and Thread.run() in Java, why calling run() directly skips new thread creation, and when each approach is appropriate.

JavaThreadConcurrencyRunnable
Diagram showing the difference between calling run() directly on the calling thread versus start() creating a new thread in Java.
Java

Java Thread run() vs start(): What's the Difference?

Calling Thread.run() directly executes on the current thread; Thread.start() creates a new thread. Learn the difference, common pitfalls, and when ExecutorService is the better choice.

JavaThreadsConcurrencyRunnable
Diagram showing a main thread calling Thread.start() which creates a new thread executing run() concurrently.
Java

Java Thread Start: How Thread.start() Works

Understand what happens when you call Thread.start() in Java, why run() doesn't start a new thread, and how to handle lifecycle, errors, and thread pools.

ThreadConcurrencyMultithreadingJava
Illustration of Java thread creation showing a main thread branching into multiple worker threads
Java

Creating Threads in Java: Runnable, Thread, and Executors

Learn how to create threads in Java using Thread subclasses, Runnable, lambdas, and ExecutorService, with guidance on choosing the right approach.

Java threadsRunnable interfaceExecutorServiceJava concurrency
Comparison of Java Thread class and Runnable interface for concurrent task execution
Java

Java Thread vs Runnable: Which to Use

Compare Java's Thread class and Runnable interface for defining concurrent tasks, and learn which approach fits different scenarios.

Java concurrencyThread classRunnable interfacemultithreading