DeprecatedStop.java
资源名称:Source.rar [点击查看]
上传用户:songled
上传日期:2022-07-14
资源大小:94k
文件大小:1k
源码类别:
进程与线程
开发平台:
Java
- public class DeprecatedStop extends Object implements Runnable {
- public void run() {
- int count = 0;
- while ( true ) {
- System.out.println("Running ... count=" + count);
- count++;
- try {
- Thread.sleep(300);
- } catch ( InterruptedException x ) {
- // ignore
- }
- }
- }
- public static void main(String[] args) {
- DeprecatedStop ds = new DeprecatedStop();
- Thread t = new Thread(ds);
- t.start();
- try {
- Thread.sleep(2000);
- } catch ( InterruptedException x ) {
- // ignore
- }
- // Abruptly stop the other thread in its tracks!
- t.stop();
- }
- }