Threads in Java

Thread:
  • Facility to allow multiple activities within a single process
  • Referred as lightweight process
  • A thread is a series of executed statements
  • Each thread has its own program counter, stack and local variables
  • A thread is a nested sequence of method calls
  • Its shares memory, files and per-process state
Need of a thread:
  • To perform asynchronous or background processing
  • Increases the responsiveness of GUI applications
  • Take advantage of multiprocessor systems
  • Simplify program logic when there are multiple independent entities
When a thread is invoked, there will be two paths of execution. One path will execute the thread and the other path will follow the statement after the thread invocation. There will be a separate stack and memory space for each thread.
Every java program creates at least one thread [ main() thread ]. Additional threads are created through the Thread constructor or by instantiating classes that extend the Thread class.

Comments

Popular posts from this blog

Flutter : Introduction

How to release your Flutter app

Firebase Cloud Messaging