Recently, there is a personal communication communication, so I will forget it here, I also hope that everyone will recommend it.
The first step is written in a thread class Commthread.java
Package com.hode.thread;
/ ** * @author Tailbo childhood * / public abstract class commthread extends thread {private boolean shoprun = false
Private int SleepTime = 2000;
PRIVATE BOOLEAN ISWAIT = FALSE;
private boolean isWork = true; / ** * * / public CommThread () {// super ( "CommThread"); Thread commThread = new Thread (CommThread.this); shouldRun = true;} public CommThread (int sleepTime) {/ / super ("CommThread"); Thread Commthread = New Thread (CommThread.this); ShouldRun = true; this.sleeptime = Sleeptime;} PUBLIC VOID ThreadStart ()};
Public void run () {while (shouldRun) {Sleep (SleepTime);} catch (interruptedException e) {system.err.println ("Thread Thread1 is unexpectedly terminated.");}} (! getWait ()) {iswork = true; system.out.println ("/ n processing start"); dispose ();
IsWork = false; system.out.println ("/ n processing");} else {iswork = false; system.out.println ("Wait ... / N");}}} public void shutdown () {ShouldRun = false;
Public void setwait (boolean bool) {iswait = bool;}
Public Boolean getWait () {return iswait;}
Public boolean getWork () {return iswork;} public abstract void dispose ();} This class is a virtual class, where the function public abstract void dispose () is part of the program that needs to be processed in the thread.