zoukankan      html  css  js  c++  java
  • 1.7.5能停止的线程-暴力停止

    使用stop方式暴力停止线程

     1 package com.cky.thread;
     2 
     3 /**
     4  * Created by edison on 2017/12/3.
     5  */
     6 public class MyThread extends Thread{
     7     private int i=0;
     8     @Override
     9     public void run() {
    10         super.run();
    11         try {
    12             while(true) {
    13                i++;
    14                 System.out.println("i="+i);
    15                 Thread.sleep(1000);
    16             }
    17         } catch (InterruptedException e) {
    18             e.printStackTrace();
    19         }
    20     }
    21 }
    package com.cky.test;
    
    import com.cky.thread.MyThread;
    
    /**
     * Created by edison on 2017/12/3.
     */
    public class Test {
        public static void main(String[] args) {
            try {
                MyThread th = new MyThread();
                th.start();
                Thread.sleep(8000);
                th.stop();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
    
    
        }
    }
    C:itsoftjdkinjava -Didea.launcher.port=7532 "-Didea.launcher.bin.path=C:itsoftideaIntelliJ IDEA 2016.3.3in" -Dfile.encoding=UTF-8 -classpath "C:itsoftjdkjrelibcharsets.jar;C:itsoftjdkjrelibdeploy.jar;C:itsoftjdkjrelibextaccess-bridge-32.jar;C:itsoftjdkjrelibextcldrdata.jar;C:itsoftjdkjrelibextdnsns.jar;C:itsoftjdkjrelibextjaccess.jar;C:itsoftjdkjrelibextjfxrt.jar;C:itsoftjdkjrelibextlocaledata.jar;C:itsoftjdkjrelibext
    ashorn.jar;C:itsoftjdkjrelibextsunec.jar;C:itsoftjdkjrelibextsunjce_provider.jar;C:itsoftjdkjrelibextsunmscapi.jar;C:itsoftjdkjrelibextsunpkcs11.jar;C:itsoftjdkjrelibextzipfs.jar;C:itsoftjdkjrelibjavaws.jar;C:itsoftjdkjrelibjce.jar;C:itsoftjdkjrelibjfr.jar;C:itsoftjdkjrelibjfxswt.jar;C:itsoftjdkjrelibjsse.jar;C:itsoftjdkjrelibmanagement-agent.jar;C:itsoftjdkjrelibplugin.jar;C:itsoftjdkjrelib
    esources.jar;C:itsoftjdkjrelib
    t.jar;C:多线程核心技术第一章outproduction第一章;C:itsoftideaIntelliJ IDEA 2016.3.3libidea_rt.jar" com.intellij.rt.execution.application.AppMain com.cky.test.Test
    i=1
    i=2
    i=3
    i=4
    i=5
    i=6
    i=7
    i=8
    
    Process finished with exit code 0

    结果分析,当i只执行到8,子线程就被暴力停止了

  • 相关阅读:
    javaWeb 使用jsp开发 if else 标签
    javaWeb 使用jsp开发 if 标签
    javaWeb 使用jsp标签进行防盗链
    javaWeb 在jsp中 使用自定义标签输出访问者IP
    javaWeb el表达式和jstl快速入门案例
    javaWeb 使用 jsp 和 javaBean 实现计算器功能
    javaWeb 使用cookie显示上次访问网站时间
    javaWeb 使用cookie显示商品浏览记录
    javaWeb request乱码处理
    ubunu下用命令设置壁纸
  • 原文地址:https://www.cnblogs.com/edison20161121/p/7954758.html
Copyright © 2011-2022 走看看