startstop.java

来自「这是一个udp接收程序」· Java 代码 · 共 46 行

JAVA
46
字号
package zjkdata;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2007</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class startstop extends Object implements Runnable {  private volatile boolean stoprequested;  private Thread runthread;  public void run()  {    runthread = Thread.currentThread();    stoprequested = false;    int i=0;    //System.out.println("线程启动!");    while(!stoprequested)    {      //System.out.println("运行次数:"+i);      i++;      try      {        Thread.sleep(2000);      }      catch(InterruptedException x)      {        //System.out.println("线程停止!");        Thread.currentThread().interrupt();        //System.out.println("线程停止了!");      }    }  }  public void stop()  {    stoprequested = true;    if(runthread != null){      runthread.interrupt();    }  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?