Multi Threading
Multi Threading
It doesn't block the user because threads are independent and you can
perform multiple operations at the same time.
You can perform many operations together, so it saves time.
Threads are independent, so it doesn't affect other threads if an
exception occurs in a single thread.
A thread is a lightweight subprocess, the smallest unit of processing. It is a separate path of execution.
Threads are independent. If there occurs exception in one thread, it doesn't affect other threads. It
uses a shared memory area.
static Thread currentThread() It returns a reference to the currently executing thread object.
static boolean interrupted() It tests whether the current thread has been interrupted.
static int activeCount() It returns the number of active threads in the current thread's thread group.
void checkAccess() It determines if the currently running thread has permission to modify the thread.
static boolean holdLock() It returns true if and only if the current thread holds the monitor lock on the specified object.
static void dumpStack() It is used to print a stack trace of the current thread to the standard error stream.
In Java, a thread always exists in any one of the following states. These
states are:
1. New
2. Active
3. Blocked / Waiting
4. Timed Waiting
5. Terminated