Friday, 21 April 2017

1. What is java concurrency



1. What is Java Concurrency
·         Concurrency is the ability to run several programs or several parts of a program in parallel.
·         Concurrency enable a program to achieve high performance and throughput by utilizing the untapped capabilities of underlying operating system and machine hardware.
·         The backbone of java concurrency are threads.
·          A thread is a lightweight process which has its own call stack, but can access shared data of other threads in the same process.
·          A Java application runs by default in one process.
·         Within a Java application you can work with many threads to achieve parallel processing or concurrency.


2. Difference between parallel, sequential, concurrency execution
Sequential execution:
·         Multiple tasks executing one after one.
·         Second task will execute once first task will be finished.
·         Eg : Conducting a class by single faculty.
Parallel execution:
·         Executing multiple tasks at a time, without any dependency of another task.
·         Eg: Conducting a classes by different faculties.
Concurrency execution:
·         Executing multiple tasks at a time by pauses the currently executing task.
·         Eg: Conducting multiple classes by single faculty at a time.


3. Types of multitasking
·         Two types of multitasking.
Process based multitasking execution:
·         Executing multiple tasks simultaneously  where each task is separate independent program(process) is called as Process based multitasking.
·         Eg : Running a java program, listening a music, downloading a movie on same System CPU
·         Each task is running in a separate address of CPU
·         Above image shows , how OS is switch the multiple tasks, each process has its own address.
Thread based multitasking execution:
·         Executing multiple tasks concurrently where each task is separate independent part of same program is called as Thread based multitasking.
·         Here each task is a separate independent part of a single process, that part is called as thread.
·         Each Thread has its own stack area for its execution.
·         At a single instance of time JVM cannot execute two tasks at a time.
·         Above fig shows that, both threads are executed in suspend – resume fashion.










No comments:

Post a Comment

3. Java Program to create Binary Tree