forked from rampatra/Algorithms-and-Data-Structures-in-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasics.java
38 lines (34 loc) · 1.02 KB
/
Basics.java
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
package com.rampatra.threads;
/**
* Created by IntelliJ IDEA.
* User: rampatra
* Date: 4/15/15
* Time: 11:27 PM
* To change this template go to Preferences | IDE Settings | File and Code Templates
*/
public class Basics {
public static void main(String[] args) {
Runnable r = new Runnable() {
@Override
public void run() {
for (int i = 0; i < 10; i++) {
System.out.println(Thread.currentThread().getName() + ": " + i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
System.out.println("====== " + Thread.currentThread().getName() + " woke up ======");
}
}
};
Thread t1 = new Thread(r);
Thread t2 = new Thread(r);
Thread t3 = new Thread(r);
t1.setName("T1");
t2.setName("T2");
t3.setName("T3");
t1.start();
t2.start();
t3.start();
}
}