java 线程自运行类
来源:互联网 发布:mongodb golang doc 编辑:程序博客网 时间:2024/05/18 00:09
public class InnerSelfRun extends Object {
private Thread internalThread;
private volatile boolean noStopRequested;
public InnerSelfRun() {
// other constructor stuff should appear here first ...
System.out.println("in constructor - initializing...");
// just before returning, the thread should be created and started.
noStopRequested = true;
Runnable r = new Runnable() { //内嵌了一个Runnable
public void run() {
try {
runWork();
} catch ( Exception x ) {
// in case ANY exception slips through
x.printStackTrace();
}
}
};
internalThread = new Thread(r); //获取当前进程,使之运行
internalThread.start();
}
private void runWork() {
while ( noStopRequested ) {
System.out.println("in runWork() - still going...");
try {
Thread.sleep(700);
} catch ( InterruptedException x ) {
// Any caught interrupts should be habitually re-asserted
// for any blocking statements which follow.
Thread.currentThread().interrupt(); // re-assert interrupt
}
}
}
public void stopRequest() {
noStopRequested = false;
internalThread.interrupt();
}
public boolean isAlive() {
return internalThread.isAlive();
}
}
- java 线程自运行类
- java 线程运行等级
- java线程运行状态
- java 线程运行状态
- Java自带线程池
- Java自带线程池
- java自带线程池
- java自带四种线程池
- 运行java线程后会有多少个线程
- java 线程后台运行示例
- [Java] Thread 线程交替运行
- Java指定周期运行线程
- java创建运行线程Thread
- Java-线程的运行状态
- 让Java程序自带JRE运行
- 201709301535->unity类自运行
- java自带的线程池ThreadPoolExecutor
- java自带线程池和队列
- 2006.11.01++
- SQLPLUS命令大全
- 养龟小记-N
- 2006.10.29+
- 【转载】软件设计中的易用性
- java 线程自运行类
- 2006.10.29++
- 2006.10.23(25)
- 2006.10.23(26)
- 微精神分析实例
- 【转载 】通用界面指南
- 【转载】界面设计、交互设计及程序开发
- 体验IE7.0,感觉PERFECT!
- XP下装sql2000随便什么版本--备忘