Multithreading

1.1 Introduction to Multithreading

Java program support Multithreading internally, by default all programs of java execute as a thread. A multithreaded program may contains more than one part that can run concurrently and each part is known as thread.
Learn More...

1.2 Process VS Thread

Both process and Thread are independent path of execution but one process can have multiple Threads.
Learn More...

1.3 Difference between Multitasking and Multithreading :

In Multitasking operating system tasks are know as heavy-weight process whereas Multithreading environment tasks are light weight process or threads.
Learn More...

1.4 Creating a Thread

There are two ways of creating threads.
Learn More...

1.5 Runnable v/s Thread

Thread is a class that is use to create threads and Runnable is a interface that use to create thread.
Learn More...

1.6 Java Thread Scheduler

In Java program, you create threads but they are not executed by Java alone. Java takes the help of the underlying OS to execute them.
Learn More...

1.7 Life Cycle Of A Thread

It is very important to understand the Life cycle of threads, when you are programming with threads. There are several forms of thread in which it reside during the execution of the program.
Learn More...

1.8 Thread Sleep() v/s Yield()

Difference between sleep() and yield() is that, yield() method pauses the currently executing thread temporarily for giving a chance to the remaining waiting threads of the same priority to execute, whereas sleep() method causes the currently executing thread to sleep for the specified number of milliseconds or nanoseconds.
Learn More...

1.9 Thread Join() method

Join method in Java has two variants one which has no argument and other which takes time in millisecond.
Learn More...

1.10 Thread isAlive() method

final boolean isAlive() method can be used to find out if a thread is alive or dead.
Learn More...

1.11 Thread Priority

Threads are assigned priorities that the thread scheduler can use to determine how the threads will be scheduled.
Learn More...

1.12 Daemon Thread

Daemon thread in Java are those thread which runs in background and mostly created by JVM for performing background task like Garbage collection and other house keeping tasks.
Learn More...

1.13 ThreadGroup

The thread group represents a set of threads.
Learn More...

1.14 ShutdownHookup

Java JVM provides you a hook to register a thread with the shutdown initiation sequence. Once a thread is registered, on every shutdown that thread is run.
Learn More...

1.15 Anonymous class use in Thread

An anonymous class in Java is a class with no specified name declared and instantiated at the same time. Because it has no name it can only be used once at place of declaration.
Learn More...

1.16 Synchronization

Threads share the same memory space, that is, they can share resources. However, there are critical situations where it is desirable that only one thread at a time has access to a shared resource. For example, crediting and debiting a shared bank account concurrently amongst several users.
Learn More...

1.17 Synchronized Methods

If the methods of an object should only be executed by one thread at a time, then the declaration of all such methods should be specified with the keyword synchronized.
Learn More...

1.18 Synchronized Block

The synchronized block allows execution of arbitrary code to be synchronized on the lock of an arbitrary object.
Learn More...

1.19 Static Methods In Synchronized Block

It's possible to synchronize a static method. When this occurs, a lock is obtained for the class itself. When we create a synchronized block in a static method, we need to synchronize on an object, so what object should we synchronize on? We can synchronize on the Class object that represents the class that is being synchronized.
Learn More...

1.20 Inter-Thread Communication

Inter-thread communication is all about making synchronized thread communicate with each other.
Learn More...

1.21 Dead Lock

A deadlock is a situation where a thread is waiting for an object lock that another thread holds, and this second thread is waiting for an object lock that the first thread holds.
Learn More...

1.22 Volatile Keyword

When multiple threads using the same variable, each thread will have its own copy of the local cache for that variable.
Learn More...