博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
后台线程的调用Thead
阅读量:7083 次
发布时间:2019-06-28

本文共 1079 字,大约阅读时间需要 3 分钟。

启动线程

List<ActionDevice> temDevice = new ArrayList<ActionDevice>();

ScheduleEexcuteThread SET=new ScheduleEexcuteThread(temDevice);

SET.start();

参数temDevice为需要操作的对象。

参数ActionDevice为实体类

线程ScheduleEexcuteThread需要继承Thread

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();

      本文转自tianjian_0913 51CTO博客,原文链接:http://blog.51cto.com/tianjian/1665987,如需转载请自行联系原作者

你可能感兴趣的文章
Android AIDL 一探究竟
查看>>
P问题、NP问题和NPC问题
查看>>
vmwear导出OVF模板解析(解决ovf导入服务器失败问题,虚拟机版本等)
查看>>
Nginx 的两种认证方式
查看>>
mysql连表分组报错---- sql_mode=only_full_group_by问题解决
查看>>
让 scrollview动起来,
查看>>
第二周作业
查看>>
Surrounded Regions
查看>>
NodeJS学习笔记之MongoDB模块
查看>>
有趣的js题目
查看>>
OVN conntrack flag
查看>>
UVa11020 · Efficient Solutions
查看>>
C# Stream篇(五) -- MemoryStream
查看>>
virtualbox ubuntu 网络连接 以及 连接 secureCRT
查看>>
【HDOJ】2459 Maximum repetition substring
查看>>
常用的端口配置
查看>>
Spark学习之路 (十四)SparkCore的调优之资源调优JVM的GC垃圾收集器
查看>>
getprop 获取android系统属性
查看>>
数组-冒泡排列
查看>>
PHP - 模拟HTTP请求, stream_context_create 和 fopen 和 fsockopen
查看>>