forked from crossoverJie/JCSprout
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStopThread.java
More file actions
36 lines (26 loc) · 858 Bytes
/
StopThread.java
File metadata and controls
36 lines (26 loc) · 858 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
34
35
36
package com.crossoverjie.concurrent;
import java.util.concurrent.TimeUnit;
/**
* Function:响应中断
*
* @author crossoverJie
* Date: 16/03/2018 01:41
* @since JDK 1.8
*/
public class StopThread implements Runnable {
@Override
public void run() {
while ( !Thread.currentThread().isInterrupted()) {
// 线程执行具体逻辑
System.out.println(Thread.currentThread().getName() + "运行中。。");
}
System.out.println(Thread.currentThread().getName() + "退出。。");
}
public static void main(String[] args) throws InterruptedException {
Thread thread = new Thread(new StopThread(), "thread A");
thread.start();
System.out.println("main 线程正在运行") ;
TimeUnit.MILLISECONDS.sleep(10) ;
thread.interrupt();
}
}