Java Multithreading


In Java, multi-threading is the process of executing multiple threads at a time.


A multi-threaded program consists of two or more parts which run simultaneously. Each part can handle a different task at the same time.


A thread is a lightweight sub-process and uses shared memory area.


Multitasking is defined as multiple processes share common processing resources of CPU.

multithreading

Advantages of Multithreading in Java

  • Multithreading enhances performance by decreasing the development time.
  • While performing multiple operations at a time, you can also save your time.
  • Threads are independent, so it does not affect other threads.
  • It is a better use of the cache storage by utilization of the resources.
  • It helps the better use of the CPU resource.

S.no Method Description
1 public void start() It starts the execution of the thread and it invokes the run() method.
2 public void run() It is invoked on that Runnable object.
3 public static void sleep(long millisec) It sleeps a thread for the specified number of milliseconds.
4 public final void setName(String name) It Changes the name of the Thread object.
5 public final void setPriority(int priority) It sets the priority of this Thread object.
6 public final void join(long millisec) It waits for a thread to die.
7 public final boolean isAlive() It checks whether the thread is alive or not.
8 int getPriority() It returns the priority of the thread.
9 public static void yield() Causes the currently executing thread object to yield and allow other threads to be scheduled.
10 public static Thread currentThread() It returns a reference to the currently executing thread object.
11 void stop() It is used to stop the thread.
12 boolean isDaemon() It check whether the thread is a daemon thread or not.
13 void interrupt() It interrupts the thread.
14 void notify() It is used to give the notification for only one thread to awake up from wait state.
14 void notifyAll() It is used to give the notification all thread to awake up from wait state.



Onlinetpoint is optimized for basic learning, practice and more. Examples are well checked and working examples available on this website but we can't give assurity for 100% correctness of all the content. This site under copyright content belongs to Onlinetpoint. You agree to have read and accepted our terms of use, cookie and privacy policy.