forked from brianway/java-learning
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathThreadTest.java
More file actions
33 lines (28 loc) · 888 Bytes
/
Copy pathThreadTest.java
File metadata and controls
33 lines (28 loc) · 888 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
package com.kenny.Thread;
public class ThreadTest {
public static void main(String[] args) throws InterruptedException {
new ThreadTest().start();
}
public void start() throws InterruptedException {
// 1.继承Thread类
try{
Thread thread1 = new ThreadA();
thread1.start();
Thread.sleep(1000);
thread1.interrupt();
}catch (InterruptedException e){
System.out.println("end");
}
// 2. 直接创建匿名内部类
Thread thread2 = new Thread(){
@Override
public void run() {
System.out.println("Thread2 is start");
}
};
thread2.start();
// 3.实现runnable接口,并 new Thread(Runnable runnable)
Thread thread3 = new Thread(new ThreadB());
thread3.start();
}
}