-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
27 lines (21 loc) · 773 Bytes
/
Copy pathTest.java
File metadata and controls
27 lines (21 loc) · 773 Bytes
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
public class Test {
public static void main(String[] args) throws Exception {
// initialize a new counter
Counter counter = new Counter();
// creating the threads
MyThread thread1 = new MyThread(counter);
MyThread thread2 = new MyThread(counter);
// starting the two threads which will execute simultaneously
thread1.start();
thread2.start();
// waiting threads execution to be finished
try {
thread1.join();
thread2.join();
} catch (Exception e) {
throw new Exception(e);
}
// after execution completion printing the count
System.out.println(counter.getCount());
}
}