Java Thread Dump: Capture with jcmd, jstack and Analyze It
Capture a Java thread dump with jcmd, jstack, kill -3 or JSON for virtual threads, read every line and find deadlocks, CPU hogs and stuck pools.
Capture a Java thread dump with jcmd, jstack, kill -3 or JSON for virtual threads, read every line and find deadlocks, CPU hogs and stuck pools.
Java concurrency interview guide lists frequently asked questions for beginners and experienced programmers to help refresh multi-threading concepts.
The Java volatile keyword makes writes visible to other threads but does not make count++ atomic. See happens-before, stop flags and lazy singletons.
Are local variables thread safe in Java? Yes, each thread keeps its own stack copy. See when shared objects, lambdas and escaping references break it.
Runnable vs Callable in Java explained with examples of return values, checked exceptions, Future, FutureTask, invokeAll and the Java 19 Future methods.
Learn what a daemon thread in Java is, how setDaemon() works, why the JVM does not wait for it, virtual threads, executors and when to use one.
Semaphore vs ReentrantLock in Java compared with a table and code for ownership, reentrancy, IllegalMonitorStateException, conditions and when to use each.
IllegalMonitorStateException in Java explained, with every cause from wait() and notify() outside synchronized to ReentrantLock unlock() and the fixes.
Java thread join() waits for another thread to finish. Learn join(long), join(Duration), interrupts, deadlocks, visibility and yield() vs join().
Java concurrency explained for Java 25 with thread safety, a race condition fix, a timeline from Java 1.0 to 25 and all our tutorials grouped by task.
How to kill a thread in Java safely with interrupt() or a volatile flag, why Thread.stop() throws UnsupportedOperationException and how to stop tasks.
Set and get the thread name in Java with getName(), setName(), constructors and Thread builders, default names, executor thread names and threadId().
Java structured concurrency with the Java 25 preview API. Learn StructuredTaskScope.open(), fork, join, Joiners, timeouts, custom joiners and the flags.
Java virtual threads explained for Java 25 with examples, carrier threads, the Java 24 pinning fix, when not to use them, pooling and ThreadLocal pitfalls.
Java DelayQueue explained with a Delayed record, take(), poll() and peek() rules, a producer-consumer order timeout example and the alternatives.
Shut down a Java ExecutorService with shutdown(), awaitTermination() and shutdownNow(), or with try-with-resources and close() on Java 19+. Covers queued tasks, RejectedExecutionException, virtual threads, JVM exit and shutdown hooks.
Learn to cancel a task in ExecutorService with Future.cancel(), stop running tasks with interrupts, cancel after a timeout and clean up with purge().
Java ScheduledExecutorService examples for delayed and periodic tasks, scheduleAtFixedRate vs scheduleWithFixedDelay, exceptions, cancel and daily jobs.
Learn how ExecutorService invokeAll() runs a batch of Callable tasks, with timeouts, failed tasks, Future.state() and invokeAny() for the first result.
A RejectedExecutionHandler decides what happens to a task that a ThreadPoolExecutor cannot accept. Compare the four built-in policies with real output and write custom handlers.
Learn ExecutorService in Java with Java 25 examples for submit(), invokeAll(), Future results, close() with try-with-resources and virtual threads.
AtomicInteger lets many threads update one int without a lock. Covers every method with results, compare-and-swap, AtomicInteger vs synchronized vs volatile, and LongAdder for high contention.
Java Hashtable is a synchronized legacy map. See how it works, why compound updates still race, HashMap vs Hashtable, and when to use ConcurrentHashMap.
Solve the producer consumer problem in Java with BlockingQueue, put() and take(), a poison pill per consumer, timeouts and virtual threads.
Learn the thread life cycle in Java with all six Thread.State values, a state diagram, runnable demos, transitions, virtual threads and thread dumps.
Concurrency vs parallelism explained with Java 25 examples, a timeline diagram, the four combinations and which Java API fits waiting or CPU-bound tasks.
Callable and Future in Java with runnable examples of get() with timeout, exceptions, cancel(), Java 19 state() and resultNow(), and FutureTask.
Java thread pool guide with Executors factory pools, a fixed size pool example, ThreadPoolExecutor settings, pool sizing, monitoring and virtual threads.
Learn how Java ConcurrentLinkedDeque works, with lock-free methods for both ends, a 100-thread example, size() limits, work stealing and deque comparison.
Java Semaphore explained with examples for acquire(), release(), tryAcquire() timeouts, fairness, throttling an executor and limiting virtual threads.
Java wait notify explained with wait(), notify() and notifyAll(), a bounded producer consumer queue, spurious wakeups and BlockingQueue.
A Java binary semaphore is a Semaphore(1). Learn how it works, when to use it, how it differs from a mutex, signaling and the over-release bug.
Use a Java Lock to let one thread at a time change shared data. Covers ReentrantLock with try-finally, tryLock() with a timeout, fair locks, ReadWriteLock, StampedLock, Condition and virtual threads.
Learn when to use Java ThreadLocal, why it leaks in thread pools, how remove() in finally fixes it, and when Java 25 ScopedValue is the better choice.
Use Java UncaughtExceptionHandler to log thread failures, restart threads with a limit, and see why ExecutorService submit() never reaches the handler.
Compare and swap (CAS) writes a new value only if a variable still holds the value we read. Learn compareAndSet(), CAS loops, VarHandle and the ABA problem in Java 25.
Java CountDownLatch example with await(), countDown() in finally, timeouts, a starting gate for tests and a comparison with CyclicBarrier and invokeAll.
Runnable vs Thread in Java compared with examples, a difference table, shared tasks, executors and virtual threads, and when extending Thread still fits.
Sleep vs wait in Java compared with Java 25 examples, covering which method keeps the lock, the thread states, wake-up rules and modern alternatives.
Object level lock vs class level lock in Java with runnable proof that the two locks are independent, syntax variants, pitfalls and virtual thread notes.
See how the ThreadPoolExecutor BlockingQueue decides when the pool grows, with SynchronousQueue, bounded and priority queues, sizing and rejected tasks.
Deadlock in Java explained with a deterministic example, jstack and ThreadMXBean detection, lock ordering, tryLock timeouts and interruptible recovery.
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.