1)Thread States: Running, New, Runnable, Blocked/Waiting, Dead
2)Context Switching: Process of storing and restoring CPU states while switching between threads
3)Join: Using this method, we can ensure serialization of thread execution.
Eg: T1, T2, T3
{
T3.start();
T3.join();
T2.Start();
T2.join();
T1.start();
}
IN the above program, JVM first encounters T3.start(). It then starts thread T3. Then parallelly it tries to execute next statement, but it encountes T3.join(), indicating JVM should continue with T3 and go to next statement until T3 is completed. Then, it starts T2...
O/P:
T3 Starts
T3 Ends
T2 Starts
T2 Ends
T1 Starts
T1 Ends
4) Difference between synchronized block and synchronized method?
Using synchronized block { } -> we can partially block some lines of a method but not the whole method. Whereas in synchronized method, the whole method will be blocked.
5) Volatile, Transient, Temporal, Atomic
6) Thread Dump: GIves info about active threads. Used to analyse the deadlock situation
7) How to prevent deadlock?
Lock ordering
Lock timeout
Dead lock detection
9) Concurrency control methods?
synchronized block - wait(), notify()
Lock api
Concurrent data structure/ collection
Volatile, Atomic
Immutable Objects
2)Context Switching: Process of storing and restoring CPU states while switching between threads
3)Join: Using this method, we can ensure serialization of thread execution.
Eg: T1, T2, T3
{
T3.start();
T3.join();
T2.Start();
T2.join();
T1.start();
}
IN the above program, JVM first encounters T3.start(). It then starts thread T3. Then parallelly it tries to execute next statement, but it encountes T3.join(), indicating JVM should continue with T3 and go to next statement until T3 is completed. Then, it starts T2...
O/P:
T3 Starts
T3 Ends
T2 Starts
T2 Ends
T1 Starts
T1 Ends
4) Difference between synchronized block and synchronized method?
Using synchronized block { } -> we can partially block some lines of a method but not the whole method. Whereas in synchronized method, the whole method will be blocked.
5) Volatile, Transient, Temporal, Atomic
6) Thread Dump: GIves info about active threads. Used to analyse the deadlock situation
7) How to prevent deadlock?
Lock ordering
Lock timeout
Dead lock detection
9) Concurrency control methods?
synchronized block - wait(), notify()
Lock api
Concurrent data structure/ collection
Volatile, Atomic
Immutable Objects
No comments:
Post a Comment