Threads In Java part 1
2 min readMar 26, 2021
Programming Language/Program (Threads)
- When a OS runs in a single processor. In runs multiples tasks such as Notepad, IE, MS-Word, Windows Explorer, Command Prompt etc. in a simultaneous manner. Because of single processor embeded in a single chip runs only one task at a time, in OS multiple tasks runs simultaneously which is managed by multi-tasking engine of the OS.
- Multi-tasking engines runs multiple tasks in 3 different models: round-robin mode, weight based model and priority model.
- This is how we call OS as multi-tasking OS. If single IC consists of multiple processors, then OS can runs multiple tasks on multiple processors running in a single IC.
- This is called as multi-processing.
- In brief multiple jobs running on a single chip on multiple processors is multi-processing.
- Multiple jobs run by a OS simultaneously on a single chip or parallelly when multiple processors exist is called as multi-tasking.
- When a command prompt is opened and on the command prompt when we run java command. It is one of task of OS.
- The java command runs JVM that loads our java program and from the single java program when we run multiple jobs then they are called as multiple threads.
- It means threads are subset of tasks, tasks are subset of process.
Tasks are controlled by OS, threads can be controlled from a java program independent of OS. This is how we can call threads as light weight (independent) process from the OS.
Threads are light-weight, controllable flow of executions in a Java program.
Originally published at https://techchannelwithdsk.blogspot.com.