-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunnableDemo.java
More file actions
33 lines (30 loc) · 999 Bytes
/
RunnableDemo.java
File metadata and controls
33 lines (30 loc) · 999 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
28
29
30
31
32
33
public class RunnableDemo implements Runnable {
private Thread thread;
private String threadName;
RunnableDemo(String name) {
threadName = name;
System.out.println("Creating " + threadName);
}
@Override
public void run() {
System.out.println("Running " + threadName);
// try {
// for (int i = 4; i > 0; i--) {
// System.out.println("Thread: " + threadName + ", " + i);
// // 让线程睡眠一会
// Thread.sleep(50);
// }
// } catch (InterruptedException e) {
// // e.printStackTrace();
// System.out.println("Thread " + threadName + " interrupted.");
// }
System.out.println("Thread " + threadName + " exiting.");
}
public void start() {
System.out.println("Starting " + threadName);
if (thread == null) {
thread = new Thread(this, threadName);
thread.start();
}
}
}