forked from greasymolue/SF-Int-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimple.java
More file actions
23 lines (21 loc) · 798 Bytes
/
Simple.java
File metadata and controls
23 lines (21 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package runnables;
public class Simple {
private static int i = 0;
public static void main(String[] args) {
Runnable counter = () -> {
System.out.println(Thread.currentThread().getName() + " worker starting");
for (; i < 10_000; i++) {
System.out.println(Thread.currentThread().getName() + " i is " + i);
}
System.out.println(Thread.currentThread().getName() + " worker ending");
};
System.out.println(Thread.currentThread().getName() + " about to start worker");
// counter.run(); // normal synchronous execution
Thread t1 = new Thread(counter);
Thread t2 = new Thread(counter);
// t1.setDaemon(true);
t1.start();
t2.start();
System.out.println(Thread.currentThread().getName() + " returned from start of worker");
}
}