-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThread.txt
More file actions
50 lines (37 loc) · 1.78 KB
/
Copy pathThread.txt
File metadata and controls
50 lines (37 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
1)diff btw wait and sleep
->sleep()
belongs to Thread Class
keep the hold on the lock
it will completes its time span specificed
static method
sleep(long millis);sleep(long millis,int nanos)
no need of sunchronized context
wait()
belongs to Object Class
releases the lock
it can completes its time span until notified
non static method
wait();wait(long millis);wait(long millis,int nanos)
should be called from synchronized context otherwise IllegalMonitorStateException
2)What is the difference between processes and threads?
->process:
An instance of program
heavy weight
independent menory
thread
subset of program
light weight
shared memory
3)Differences Between Lock API and Synchronized Block
1)lock and unlock operation can be done from separate methods.Unlike synchronized block which is present inside a single method.
2)trylock enable thread to avoid getting blocked when other thread has a hold on the lock
3)Based on condition we can make the thread to enter wait state(Condition interface)
4)Lock provides fair lock management.It can allow long waiting thread to aquire lock
4)What are some of the improvements in Concurrency API in Java 8?
->ConcurrentHashMap compute(), forEach(), forEachEntry(), forEachKey(), forEachValue(), merge(), reduce() and
search() methods.
CompletableFuture that may be explicitly completed (setting its value and status).
Executors newWorkStealingPool() method to create a work-stealing thread pool using all available processors as its target parallelism level.
5)diff btw Collection.synchronizedList() and CopyOnWriteArrayList
Write a program that will result in a deadlock. How will you fix deadlock in Java?
How can we implement Producer-Consumer problem using Blocking Queue?