Difference Between Callable and Runnable
Learn about Java Runnable and Callable Interfaces with simple examples and some of the main usages and differences between both interfaces.
CARVIEW |
Learn about Java Runnable and Callable Interfaces with simple examples and some of the main usages and differences between both interfaces.
Learn what is a daemon thread in Java, how to create a daemon thread, and various methods present for daemon threads in the Thread class.
Learn InterruptedException and when it is thrown with examples. We will also see how we can handle this exception in our code.
Learn the need and methods to join two threads in Java with examples. Learn to set wait expiration time and avoid thread deadlock conditions.
Learn the different ways of creating and starting new threads using Thread class, Runnable interface, ExecutorService and virtual threads.
In this post, we are going to discuss thread priorities in detail and the different types of thread priorities in Java, and how a thread scheduler executes various threads based on their priorities. We will also see how we can set thread priority of a thread and how we can …
Learn to kill a running thread in Java using a boolean flag and sending interrupt message. Sending an interrupt is a much better approach.
Learn the different ways to set a custom name for a thread using Thread constructor and setName(). Also, learn to get the name of a thread.
Learn about the lifecycle of a Thread in Java, and how the state transitions happen between different states of the Thread by JVM and OS.
The Object class in Java has three final methods that allow threads to communicate i.e. wait(), notify() and notifyAll(). Learn how to use these methods.
The factory design pattern is one of the most used design patterns in the java. It is one of creational patterns and can be used to develop an object in demand of one or several classes. With this factory, we centralize the creation of objects. The centralization of creation logic …
Today, one of the most critical aspects of a concurrent application is shared data. When you create a thread that implements the Runnable interface and then starts various Thread objects using the same Runnable object. All the threads share the same attributes that are defined inside the runnable object. This …
1. UncaughtExceptionHandler Java applications have two kind of exceptions – checked exceptions and unchecked exceptions. Checked exceptions must be specified in the throws clause of a method or caught inside them. Unchecked exceptions don’t have to be specified or caught. When a checked exception is thrown inside the run() method …
Multi-threading is very popular topic among interviewers from long time. Though I personally feel that very few of us get real chance to work on a complex multi-threaded application (I got only one chance in last 7 years), still it helps in having the concepts handy to boost your confidence …
Defining thread safety is surprisingly tricky. A quick Google search turns up numerous “definitions” like these: Thread-safe code is code that will work even if many Threads are executing it simultaneously. A piece of code is thread-safe if it only manipulates shared data structures in a manner that guarantees safe …
In Java Concurrency, until we have a particular reason, it is always recommended to implement the Runnable interface to create new threads.
Learn the differences between sleep() and wait() methods in Java. Learn when o use which method and what effect they bring in Java concurrency.
A thread dump is a list of all the Java threads that are currently active in a Java Virtual Machine (JVM). There are several ways to take thread dumps from a JVM. It is highly recommended to take more than 1 thread dump while analyzing any problem such as deadlock …
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.