FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaExamples/SynchronizationDemo4DeadLock.java at master · alimogh/JavaExamples · GitHub
alimogh
/
JavaExamples
Public
forked from
CMPundhir/JavaExamples
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaExamples
/
SynchronizationDemo4DeadLock.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (36 loc) · 1.07 KB
Breadcrumbs
JavaExamples
/
SynchronizationDemo4DeadLock.java
Copy path
File metadata and controls
37 lines (36 loc) · 1.07 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
class
SynchronizationDemo4DeadLock
{
public
static
void
main
(
String
[]
args
){
final
String
res1
=
"Icecream"
;
final
String
res2
=
"Chocolate"
;
Thread
t1
=
new
Thread
(){
public
void
run
(){
synchronized
(
res1
){
System
.
out
.
println
(
res1
+
" is locked by "
+
getName
());
try
{
Thread
.
sleep
(
200
);}
catch
(
Exception
e
){}
synchronized
(
res2
){
System
.
out
.
println
(
res2
+
" is locked by "
+
getName
());
try
{
Thread
.
sleep
(
200
);}
catch
(
Exception
e
){}
System
.
out
.
println
(
res2
+
" is released by "
+
getName
());
}
System
.
out
.
println
(
res1
+
" is released by "
+
getName
());
}
}
};
t1
.
start
();
Thread
t2
=
new
Thread
(){
public
void
run
(){
synchronized
(
res2
){
System
.
out
.
println
(
res2
+
" is locked by "
+
getName
());
try
{
Thread
.
sleep
(
200
);}
catch
(
Exception
e
){}
synchronized
(
res1
){
System
.
out
.
println
(
res1
+
" is locked by "
+
getName
());
try
{
Thread
.
sleep
(
200
);}
catch
(
Exception
e
){}
System
.
out
.
println
(
res1
+
" is released by "
+
getName
());
}
System
.
out
.
println
(
res2
+
" is released by "
+
getName
());
}
}
};
t2
.
start
();
}
}
Back
|
FazBrowse Home
|
New Git URL