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;thread stop不错呀
NULL 博文链接:https://yxhcquedu.iteye.com/blog/859199
针对这个问题:https://www.ilovematlab.cn/thread-23233-1-1.html 现在我做一个集中解答,从mathworks那里学习了一下。 第一步:创建你自己的Simulink模型,这个不用我讲吧,我们使用以下模型做演示: ...
针对这个问题:https://www.ilovematlab.cn/thread-23233-1-1.html 现在我做一个集中解答,从mathworks那里学习了一下。 第一步:创建你自己的Simulink模型,这个不用我讲吧,我们使用以下模型做演示: ...
针对这个问题:https://www.ilovematlab.cn/thread-23233-1-1.html 现在我做一个集中解答,从mathworks那里学习了一下。 第一步:创建你自己的Simulink模型,这个不用我讲吧,我们使用以下模型做演示: ...
//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...
// 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,...
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.
no5_thread_stop 停止线程的几种方法 no6_deadlock 模拟死锁 no7_threadlocal ThreadLocal实例及源码解析 no8_volatile volatile实例 no9_daemon_thread 守护线程实例 no10_threadgroup 线程组 no11_...
文章目录一、threading模块介绍二、:threading模块主要对象三、threading.Thread对象1、语法2、参数3、常用方法四、python开启线程的两种方法1、使用threading.Thread 线程对象2、继承父类threading.Thread五、...
主要介绍了python中的线程threading.Thread()使用详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
if (listener == Thread.currentThread()) ex.printStackTrace(); } finally { handlers.removeElement(this); } try { dataIn.close(); } catch (IOException ioException) { ioException....
在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 *...
If you don’t stop and look around once in a while, you could miss it. 人生匆匆,若不偶尔停下来看看周围,便会错过许多风景。 一、串口数据不定长接收的实现 通常在裸机中,我们使用一个定时器来辅助串口实现...
1 前言 虽然说Python的运行效率比不过...Python3 通过两个标准库 _thread 和 threading 提供对线程的支持,不过threading基本可以完虐_thread,_thread 提供了低级别的、原始的线程以及一个简单的锁,它相比于 threadi
Thread.currentThread().interrupt(); } } }); } Or the same thing using guice: public void startGuiceServer() { final NiftyBootstrap bootstrap = Guice.createInjector( Stage.PRODUCTION, new ...
【RT-Thread作品秀】Art-pi机械臂控制作者:李志青 概述5G时代物联走入更多行业与领域,使用广和通的L610在模块,通过MQTT与中国移动onenet互联,也尝试搭建了本地MQTT服务器,适合内部布署,其再加入柿饼派两块,...
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 ...
在JDK1.2中,Thread.stop、Thread.suspend以及其他许多线程相关的方法都因为它们不安全而不推荐使用了。下面的方法展示了你用Thread.stop可以实现的可怕事情之一