Topics

6/recent/ticker-posts

Threads In Java part 1

Threads in Java 



  • What is the difference between process, task and thread?

        Programming Language/Program (Threads)
                                     |
                    Operating System (Tasks)
                                 |
                        Processor (process)

  • What is a Process?

  1. 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. 
  2. Multi-tasking engines runs multiple tasks in 3 different models: round-robin mode, weight based model and priority model.
  3.  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. 
  4. 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.

  1. When a command prompt is opened and on the command prompt when we run java command. It is one of task of OS. 
  2. 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.
  3. It means threads are subset of tasks, tasks are subset of process.

  • Tasks are uncontrollable flow of execution because we can start and stop the task execution but we cannot suspended them or sleep them or resume them.

  • Whereas when threads are started, using java threads API we can start, sleep, suspend and wait the thread executions. This is how we can threads as controllable flow of execution in a java program.

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.

  • SSS model => Sequential, Simultaneous, Synchronous

Post a Comment

1 Comments

  1. Thanks for uploading and this blogger is so nice design and lot pf information available in this blooger .keep it up👍👍

    ReplyDelete