An object consists of some data along with a set of subroutines that manipulate that data. (An object is a kind of “module” or self-contained entity that communicates with the rest of the world through a well-defined interface. An object must represent some coherent concept or real-world object.)

The Java platform is designed from the ground up to support concurrent programming, with basic concurrency support in the Java programming language and Java class libraries.

The two basic units of execution in concurrent programming in relation to the Java programming language.

In concurrent programming, there are two basic units of execution: processes and threads. In the Java programming language, concurrent programming deals primarily with threads.

Java provides built-in support for multithreaded programming. This is where a program contains two or more parts that can run simultaneously. Each part of such a program is called a thread, and each thread defines a separate execution path.

It is a specialized form of multitasking and requires less overhead than multitasking.

I need to define another term related to threads: process: A process consists of the memory space allocated by the operating system that can contain one or more threads. A thread cannot exist by itself; It must be part of a process. A process remains running until all non-daemon threads have finished executing.

This allows you to write highly efficient programs that make the most of the CPU, since idle time can be kept to a minimum.

Life cycle of a thread:

  • New – A new thread begins its life cycle in the new state. It remains in this state until the program starts the thread. It is also known as born thread.
  • Runnable: After a newborn thread is started, the thread becomes runnable. A thread in this state is considered to be executing its task.
  • Waiting: Sometimes a thread enters the waiting state while waiting for another thread to perform a task.
  • Timed-Wait: A runnable thread can enter the timed-wait state for a specified interval of time. A thread in this state returns to the runnable state when that time interval expires or when the event it is waiting for occurs.
  • Terminated – A runnable thread enters the terminated state when it completes its task or otherwise terminates.