controlledthread.java
来自「java的线程类演示」· Java 代码 · 共 41 行
JAVA
41 行
public class ControlledThread extends Thread
{
static final int RUN = 0;
static final int SUSP = 1;
static final int STOP = 2;
private int state = RUN;
public synchronized void setState(int s)
{
state = s;
if (state == RUN)
notify();
}
public synchronized boolean checkState()
{
while (state == SUSP)
{
try {
wait();
}
catch (InterruptedException e) { }
}
if (state == STOP)
return false;
return true;
}
public void run()
{
while (true)
{
//some code to run
if ( !checkState() )
break;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?