标签:thead
List<ActionDevice> temDevice = new ArrayList<ActionDevice>();
ScheduleEexcuteThread SET=new ScheduleEexcuteThread(temDevice);
SET.start();
参数temDevice为需要操作的对象。
参数ActionDevice为实体类
public class ScheduleEexcuteThread extends Thread{
Logger log = Logger.getLogger(Class.class.getName());
public List<ActionDevice> Dealy = new ArrayList<ActionDevice>();
public List<ActionDevice> tempDealy = new ArrayList<ActionDevice>();
Boolean stop=false;
public ScheduleEexcuteThread(List<ActionDevice> dDealy){
this.Dealy=dDealy;
}
public void run(){
while(!stop){
for(ActionDevice adevice :Dealy){
//对不符合条件的对象加入临时list中
tempDealy.add(adevice);
}
Dealy.clear();
Dealy.addAll(tempDealy);
tempDealy.clear();
if(Dealy.size()==0){
this.stop=true;
}else{
try {
Thread.sleep();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
定义参数stop,当条件成熟时,设置stop=true;等待下一次线程启动时,会判断stop=true,之后进程结束。
ScheduleEexcuteThread SET=new ScheduleEexcuteThread(temDevice);
SET.start();
标签:thead
原文地址:http://tianjian.blog.51cto.com/3549910/1665987