About Java time thread specific calls and releases

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.