内部线程
来源:互联网 发布:mac好用的翻墙软件 编辑:程序博客网 时间:2024/04/28 12:31
public class SelfRun implements Runnable
{
private Thread internalThread;
private volatile boolean noStopRequested;
public SelfRun()
{
System.out.println( "in constructor - initializing..." );
noStopRequested = true;
internalThread = new Thread( this );
internalThread.start();
}
public static void main(String[] args)
{
SelfRun sr = new SelfRun();
try
{
Thread.sleep( 3000 );
}catch( InterruptedException x )
{
}
sr.stopRequest();
}
public void run()
{
if( Thread.currentThread()!=internalThread )
{
throw new RuntimeException( "only the internal " +
"thread is allowed to invoke run()" );
}
while( noStopRequested )
{
System.out.println( "in run() - still going..." );
try
{
Thread.sleep( 700 );
}catch( InterruptedException x )
{
Thread.currentThread().interrupt();
}
}
}
public void stopRequest()
{
noStopRequested = false;
internalThread.interrupt();
}
public boolean isAlive()
{
return internalThread.isAlive();
}
}
///////////////////////////////////////////////////////////////////
in constructor - initializing...
in run() - still going...
in run() - still going...
in run() - still going...
in run() - still going...
in run() - still going...
- 内部线程
- 内部线程
- jvm内部线程介绍
- linphone 内部线程分析
- linphone 内部线程分析
- 线程的内部机制
- linphone 内部线程分析
- linphone 内部线程分析
- tcp内部线程池
- weblogic内部线程协作
- java 内部工作线程介绍
- java 5.0 内部线程池
- VM 内部运行线程介绍
- Executor内部如何创建线程?
- java 内部工作线程介绍
- JVM 内部运行线程介绍
- JVM 内部运行线程介绍
- JVM 内部运行线程介绍
- 编译器的整体构架
- 好Cool的相册!不知道大家有没有看到左侧的相片夹呢
- 面试技巧汇总:16个经典面试问题回答思路
- 面试官最爱提的15个问题
- 面试:“十大必考题”揭幕
- 内部线程
- Weblogic startAP-cluster-01.sh
- javascript中select和div
- 论坛上为何少见普通中老年人? 【圣诞节不但只是关注圣诞“老人”】
- HTTP应答状态
- 使ssh不用输入密码
- 关于宗教的
- Web服务器日志统计分析完全解决方案
- 用来获取网页的类