Thread Introduction


  
A thread is a small independent executable code within a Program.
  • A program can have multiple threads.
  • Multiple thread can use the state of shared resources.
  • Thread can be created by three ways
  • 1) java.lang.Runnable Interface (since JDK 1.0)
  • 2) java.util.concurrent.Callable Interface  (sice JDK 1.5)
  • 3) java.lang.Thread class (since JDK 1.0)
  • Each program is having a one thread. It is a main thread.
  • Each thread is having a name and priority (1 to 10).
  • Based on the priority each thread get a chance to utilize the CPU.
  • By default thread inherits priority from its parent thread.
  • Priority can also be set programmatically.
  • Higher Priority thread get first chance.
  • Similar priority thread get chance randomly. 
  • Thread class has three priority constants
  • public static int MIN_PRIORITY  ( 1)
  • public static int NORM_PRIORITY (5)
  • public static int MAX_PRIORITY (10)