I have written a set of verification code system, but the call process can not be released, the correct code after the Study:
/**
* Verification Code System
* */
public class Diyyzm extends TimerTask {
private static Timer _timer = new Timer (); Initialize a Timer object first
Initialize variables
public static String _result;
public static int _i= 0;
public static L2pcinstance _player;
Used to determine whether a thread is running
public static Boolean isrun = true;
Call Close Thread
public void Stopme () {
Cancel (); Terminating a thread
System.GC (); Freeing memory
}
Start Thread Timer
public void Startme () {
_timer.scheduleatfixedrate (new diyyzm (), 0, 1000);
}
public void Run () {
While (isrun) {
_i++;
try {
Thread.Sleep (1000);
} catch (interruptedexception E) {
}
If (_i >= 5) {//timeout 5 seconds after automatic kill
Isrun = false; Switch off
STOPME ();//terminating Thread
}
}
}
}
The Verification Code system initializes the system variables each time the call is Initialized.
Diyyzm Yzm = new Diyyzm ();
Yzm.isrun = true; Initialize variables
Yzm._i = 0; Initialize variables
Yzm.sanyzm (activechar);
About Java time thread specific calls and releases