Runnable vs Callable in Java: Differences With Examples
Runnable vs Callable in Java explained with examples of return values, checked exceptions, Future, FutureTask, invokeAll and the Java 19 Future methods.
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.
How to handle InterruptedException in Java correctly. Propagate it or restore the interrupt flag, avoid common mistakes, and cancel executor tasks.
Java thread join() waits for another thread to finish. Learn join(long), join(Duration), interrupts, deadlocks, visibility and yield() vs join().
Learn to create and start a thread in Java with Runnable, Thread, Thread.ofPlatform(), virtual threads, ExecutorService, ThreadFactory and priority.
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().
Learn the thread life cycle in Java with all six Thread.State values, a state diagram, runnable demos, transitions, virtual threads and thread dumps.
Java wait notify explained with wait(), notify() and notifyAll(), a bounded producer consumer queue, spurious wakeups and BlockingQueue.
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.
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.
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.