• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/8

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

8 Cards in this Set

  • Front
  • Back

concurrency what ,why ,how

running multiple threads to do part of a work in prallel ,


To do fast work , increase throughput, reduce time


by running multiple threads to do parts of job, async work

process/Threads what are they , differences

process is a running programe


thread is lighweight process as uses shared memory of process ,


once process can have multi thread


thread has it's own call stack , but reads from process shared memory as well

advantage and disadvantage of concurrency or multiThreaded environment , emphasise on multi Thread word

fast work , less time , use of multi core cpu


access , visibility are the issues ,


access --> two thread wants to access the same variable , race condition


deadlock


visibility -- changes done by one thread not visible to other threads



how to get rid / reduce of disadvantages ,

use of synchronized block for a code block(with a lock object) or for a method,ensure with lock


public synchronized void critial() { // some thread critical stuff // here} is a sync method



what's a volatile qualifier

the volatile keyword in Java is used as an indicator to Java compiler and Thread that do not cache value of this variable and always read it from main memory , used as a form of synchronization

properties of volatile keyword , advantages , how to use , when to use

1)values will always be read from main memory, no thread will cache it


2)read/write becomes atomic , as every thread has to read from one variable


3)only in multi thread environment you should use , there only make sense

Special uses of volatile , what can be done so great , with that atomicity , synchronisation

1)read of long and double can be atomic as 64 bit . 32 bit platform can read/write only 32 bit at once so advantageous over there


2) visibility can be achieved as all has to read same variable


3)advantageous over sync keyword as no wait , lock etc fast and easy to use

example of volatile

public class Singleton{ private static volatile Singleton _instance; //volatile variable public static Singleton getInstance(){ if(_instance == null){ synchronized(Singleton.class){ if(_instance == null) _instance = new Singleton(); } } return _instance; }