forked from Beerkay/JavaMultiThreading
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
50 lines (46 loc) · 1.63 KB
/
App.java
File metadata and controls
50 lines (46 loc) · 1.63 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
package Deadlock_11;
/**
* <a href="https://wikipedia.org/wiki/Deadlock">Deadlock</a>
* can occur in a situation when a thread is waiting for an object's lock,
* that is acquired by another thread and the second thread is waiting for an
* object lock that is acquired by first thread. Since, both threads are waiting
* for each other to release the lock, the condition is called deadlock. If you
* make sure that all locks are always taken in the same order by any thread,
* deadlocks cannot occur.
* <br><br>
* Codes with minor comments are from
* <a href="http://www.caveofprogramming.com/youtube/">
* <em>http://www.caveofprogramming.com/youtube/</em>
* </a>
* <br>
* also freely available at
* <a href="https://www.udemy.com/java-multithreading/?couponCode=FREE">
* <em>https://www.udemy.com/java-multithreading/?couponCode=FREE</em>
* </a>
*
* @author Z.B. Celik <celik.berkay@gmail.com>
*/
public class App {
public static void main(String[] args) throws Exception {
final Runner runner = new Runner();
Thread t1 = new Thread(new Runnable() {
public void run() {
try {
runner.firstThread();
} catch (InterruptedException ignored) {}
}
});
Thread t2 = new Thread(new Runnable() {
public void run() {
try {
runner.secondThread();
} catch (InterruptedException ignored) {}
}
});
t1.start();
t2.start();
t1.join();
t2.join();
runner.finished();
}
}