Call thead for a background thread

Source: Internet
Author: User

Start Thread

list<actiondevice> temdevice = new arraylist<actiondevice > ();

Scheduleeexcutethread set= New Scheduleeexcutethread (temdevice);

Set.start ();

Parameters Temdevice is the object that needs to be manipulated.

Parameters Actiondevice as an entity class

ThreadsScheduleeexcutethreadneed to inheritThread

p Ublic &NBSP; class   scheduleeexcutethread  extends

logger    = logger. getlogger Span style= "font-family: ' Courier New '; Color:rgb (0,0,0); font-size:13px;" > (Class. class .getname ());

p Ublic   list< actiondevice>   Dealy &NBSP;=&NBSP; new  arraylist< Actiondevice> ();

p Ublic   list< actiondevice>  Tempdealy &NBSP;=&NBSP; Span style= "font-family: ' Courier New '; Color:rgb (127,0,85); font-weight:bold;font-size:13px;" >new &NBSP; a rraylist<actiondevice> ();

Boolean Stop = false ; 

Public scheduleeexcutethread(list<actiondevice> ddealy) {

this . dealy =ddealy;

}

Public void run () {

while (! Stop ){

for (actiondevice adevice:dealy) {

Adding a temporary list to an object that does not meet the criteria

tempdealy. Add (adevice);

   }

dealy. Clear ();

dealy. AddAll (tempdealy);

tempdealy. Clear ();

         if ( dealy .size () ==0) {

               this =

}else{

try {

            thread. sleep ();

} catch (Interruptedexception e) {

e.printstacktrace ();

            }

      }

    }

}

}

Defining Parameters Stop , when the condition is ripe, set stop=true; waiting for the next thread to start, it will determine stop=true , and then the process ends.


Scheduleeexcutethread set= New Scheduleeexcutethread (temdevice);

Set.start ();




Call thead for a background thread

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.