workerthread.java
来自「java 完全探索的随书源码」· Java 代码 · 共 39 行
JAVA
39 行
public class WorkerThread extends Thread{ // Boolean flag that keeps state about when the thread should stop boolean keepRunning = true; // Default Constructor public WorkerThread( ThreadGroup group, String threadName ) { super( group, threadName ); } // Override the parents run method to do something special public void run() { // While the thread should keep running while( getKeepRunning() ) { System.out.println( "Thread " + getName() + " is Running" ); try { // Sleep for a time sleep( 3000 ); } catch( Exception ex ) { /* Don't do anything here */ } } // Let the user know that this thread is exiting System.out.println( "Thread: " + getName() + " is stopping" ); } // public setting method to stop the thread public synchronized void setKeepRunning( boolean trueOrFalse ) { keepRunning = trueOrFalse; } // public accessor for gettting the state of this thread public synchronized boolean getKeepRunning() { return keepRunning; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?