Java — Multithreading Enhancement | Code Factory

Code Factory
2 min readJun 3, 2020

--

Index Page : Link

Donate : Link

WordPress Blog : Link

  • Based on functionality we can group threads into a single unit which is nothing but Thread Group that is Thread Group contains a group of threads.
  • In addition to threads, Thread Group can also contain sub thread groups.
  • The main advantage of maintaining threads in the form of thread group is we can perform common operations very easily.
  • Every thread in Java belongs to some group.
  • Main thread belongs to main group.
  • Every thread group in Java is a child group of system group either directly or indirectly. Hence system group act as root for all thread groups in Java.
  • * System group contains several system level threads like finalizar, refernce handler, signal dispatcher, attach listener.
package com.example.thread;public class Test {
public static void main(String... args) {
System.out.println(Thread.currentThread().getThreadGroup().getName()); // main
System.out.println(Thread.currentThread().getThreadGroup().getParent().getName()); // system

//Thread.currentThread() --> main thread
//Thread.currentThread().getThreadGroup() --> main thread group
//Thread.currentThread().getThreadGroup().getParent() --> system thread group
}
}
  • Thread Group is a Java class present in java.lang package and it is direct child class of Object.
  1. Constructors of ThreadGroup Class
  2. Important Methods of ThreadGroup Class
  3. java.util.concurrent package
  4. java.util.concurrent.locks.Lock Interface
  5. java.util.concurrent.locks.ReentrantLock
  6. Thread Pools (Executor Framework)
  7. Callable & Future
  8. ThreadLocal

--

--