Sunday, October 11, 2015

Processes vs. Threads in Java


In concurrent programming there are two basic units of execution : processes and threads.
The main point of using concurrent programming is to have the ability of multitasking . Multitasking is a process of executing multiple tasks simultaneously. 

Some of  benefit of multitasking is to reduces time by doing many things at the time, and to utilize the CPU.  Multitasking can be achieved by two ways :
  1. Process-based (Multiprocessing) : is the execution of multiple concurrent software processes at any one instance.
  2. Thread-based (Multithreading ): is the ability to run several part/operations of a program in parallel. So you can subdivide these operations within single application into individual threads.   

 Process Vs Threads

In java we mostly concentrate on threads. However, processes are also important. Her are the basic deference between process and thread:

  •  Both Threads and processes run independently:  A process runs independently and isolated of other processes, while threads are also called lightweight process which have their own call stack 
  • Access shared data: process cannot directly access shared data in another process, while threads can. 
  • Cost of communication is very high between processes while its very low between threads. 
  • Processes are typically independent, while threads exist as subsets of a process (see below).     


No comments:

Post a Comment

Generate a unique N letters word sequence (by using relationship between Factoradic base system and Lexicographic Permutation Order of a String)

Lets say that you want to generate a unique 3 letters code sequence to be used as a primary key for some data recodes. Also let assume ...