`
kingbinchow
  • 浏览: 122944 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

stop thread

    博客分类:
  • java
阅读更多
class MyThread extends Thread{
        private volatile boolean isStop = false;
        @Override
        public void run() {
            int i = 0;
            while(!isStop){
                i++;
            }
        }
         
        public void setStop(boolean stop){
            this.isStop = stop;
        }
    }


public class Test {
     
    public static void main(String[] args) throws IOException  {
        Test test = new Test();
        MyThread thread = test.new MyThread();
        thread.start();
        try {
            Thread.currentThread().sleep(2000);
        } catch (InterruptedException e) {
             
        }
        thread.interrupt();
    } 
     
    class MyThread extends Thread{
        @Override
        public void run() {
            int i = 0;
            while(!isInterrupted() && i<Integer.MAX_VALUE){
                System.out.println(i+" while循环");
                i++;
            }
        }
    }
}
分享到:
评论

相关推荐

    thread stop tools

    thread stop;thread stop不错呀

    为什么不鼓励使用 Thread.stop?

    NULL 博文链接:https://yxhcquedu.iteye.com/blog/859199

    在MatlabGUI里面启动或者暂停Simulink模型-start_and_stop.mdl

    针对这个问题:https://www.ilovematlab.cn/thread-23233-1-1.html 现在我做一个集中解答,从mathworks那里学习了一下。 第一步:创建你自己的Simulink模型,这个不用我讲吧,我们使用以下模型做演示: ...

    在MatlabGUI里面启动或者暂停Simulink模型-start_and_stop_gui.fig

    针对这个问题:https://www.ilovematlab.cn/thread-23233-1-1.html 现在我做一个集中解答,从mathworks那里学习了一下。 第一步:创建你自己的Simulink模型,这个不用我讲吧,我们使用以下模型做演示: ...

    在MatlabGUI里面启动或者暂停Simulink模型-start_and_stop_gui.m

    针对这个问题:https://www.ilovematlab.cn/thread-23233-1-1.html 现在我做一个集中解答,从mathworks那里学习了一下。 第一步:创建你自己的Simulink模型,这个不用我讲吧,我们使用以下模型做演示: ...

    EZ-USB 例程(C#)

    //Makes the thread stop and aborts the thread bRunning = false; StartBtn.Text = "Start"; StartBtn.BackColor = Color.Aquamarine; if (tXfers == null) return; if (tXfers.IsAlive) { tXfers.Abort...

    2D弹性球动画(对初学者很有参考价值)

    // A flag to ask the thread to stop /** This method simply draws the circle at its current position */ public void paint(Graphics g) { g.setColor(Color.red); g.fillOval(x - r, y - r, r * 2,...

    weblogic jms c程序

    I am working with BEA-JMS C API in my project....handling is not receiving the signal.Some internal thread is abrubly stop and the whole aplication stop without any futher execution in main function.

    mylty_thread_review

    no5_thread_stop 停止线程的几种方法 no6_deadlock 模拟死锁 no7_threadlocal ThreadLocal实例及源码解析 no8_volatile volatile实例 no9_daemon_thread 守护线程实例 no10_threadgroup 线程组 no11_...

    【python内功修炼006】:基于threading模块的多线程操作(详解)

    文章目录一、threading模块介绍二、:threading模块主要对象三、threading.Thread对象1、语法2、参数3、常用方法四、python开启线程的两种方法1、使用threading.Thread 线程对象2、继承父类threading.Thread五、...

    python中的线程threading.Thread()使用详解

    主要介绍了python中的线程threading.Thread()使用详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

    JAVA实现SOCKET聊天

    if (listener == Thread.currentThread()) ex.printStackTrace(); } finally { handlers.removeElement(this); } try { dataIn.close(); } catch (IOException ioException) { ioException....

    带有录像接口的LibVLC库(32位x86版本)

    在LibVLC增加了 libvlc_media_player_recorder_start和libvlc_media_player_recorder_stop这两个接口。定义是: LIBVLC_API int libvlc_media_player_recorder_start ( libvlc_media_player_t *p_mi, const char *...

    消息队列方式实现串口数据不定长接收 —- RT-thread&STM32

    If you don’t stop and look around once in a while, you could miss it. 人生匆匆,若不偶尔停下来看看周围,便会错过许多风景。 一、串口数据不定长接收的实现 通常在裸机中,我们使用一个定时器来辅助串口实现...

    python3 多线程篇1

    1 前言 虽然说Python的运行效率比不过...Python3 通过两个标准库 _thread 和 threading 提供对线程的支持,不过threading基本可以完虐_thread,_thread 提供了低级别的、原始的线程以及一个简单的锁,它相比于 threadi

    thrift服务端和客户端实现Nifty.zip

    Thread.currentThread().interrupt(); } } }); } Or the same thing using guice: public void startGuiceServer() { final NiftyBootstrap bootstrap = Guice.createInjector( Stage.PRODUCTION, new ...

    【RT-Thread作品秀】Art-pi机械臂控制-电路方案

    【RT-Thread作品秀】Art-pi机械臂控制作者:李志青 概述5G时代物联走入更多行业与领域,使用广和通的L610在模块,通过MQTT与中国移动onenet互联,也尝试搭建了本地MQTT服务器,适合内部布署,其再加入柿饼派两块,...

    java多线程机制 -- 源码详解

    java多线程机制: 例子 1 public class Example1 { static Lefthand left;static Righthand right; public static void main(String args[]) { left=new Lefthand();... else if(Thread.currentThread()==right) ...

    获得当前时间并且停止或开始时间

    Thread th; public Time(String title){ super(title); setSize(200,200); setLocation(100,100); label=new Label(); stopButton=new Button("stop"); startButton=new Button("start"); pa=new ...

    java解惑--异常地危险

    在JDK1.2中,Thread.stop、Thread.suspend以及其他许多线程相关的方法都因为它们不安全而不推荐使用了。下面的方法展示了你用Thread.stop可以实现的可怕事情之一

Global site tag (gtag.js) - Google Analytics