概述
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
Master_thread master = new Master_thread();
master.getPps();
int taskSize = 4;
int threadCount = 0;
// 创建一个线程池
ExecutorService pool = Executors.newFixedThreadPool(taskSize);
//HashMap jobList = new HashMap();
Hashtable jobList = new Hashtable();
JSONArray dataList = null;
//ArrayList arrayList = (ArrayList) Collections.synchronizedList(new ArrayList<>());
for (;;)
{
System.out.println("started");
System.out.println((int)(System.currentTimeMillis() / 1000));
try {
// System.runFinalization();
//System.gc();
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//取得10条待转译数据
dataList = new JSONArray();
try {
dataList = master.getList(taskSize);
} catch (Exception e1) {
//e1.printStackTrace();
dataList = new JSONArray();
}
System.out.println("get data");
//最多10个线程
threadCount = ((ThreadPoolExecutor)pool).getActiveCount();
System.out.println("getData finished");
System.out.println("thread_count:"+threadCount);
System.out.println("jobList_size:"+jobList.size());
if(threadCount!=jobList.size())
{
for(Iterator iterator=jobList.keySet().iterator();iterator.hasNext();)
{
Integer key=iterator.next();
System.out.println("key-----"+key);
}
}
if(threadCount>=taskSize || jobList.size()>=taskSize)
{
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
continue;
}
int nums = dataList.size();
if(nums==0 && threadCount==0 && jobList.size()==0)
{
System.out.println("no data");
//master.randomResetData();
}
//遍历所有线程的记录,如果新取得的数据不存在于正在执行的任务中记录数据id并创建新线程
for(int i=0;i
{
JSONObject object = dataList.getJSONObject(i);
if(jobList.containsKey(object.getIntValue("id")))
{
System.out.println("is exists");
continue;
}
threadCount = ((ThreadPoolExecutor)pool).getActiveCount();
if(threadCount>=taskSize || jobList.size()>=taskSize)
{
System.out.println("is full");
continue;
}
pool.execute(new Job_thread(object,jobList));
jobList.put(object.getIntValue("id"), object);
System.out.println("thread created");
//System.runFinalization();
//System.gc();
System.out.println("gcs");
}
}
Job_thread run的最后会执行
最后
以上就是等待香水为你收集整理的java 工程 不停运行_做一个不停运行的服务,while true莫名其妙会死掉的全部内容,希望文章能够帮你解决java 工程 不停运行_做一个不停运行的服务,while true莫名其妙会死掉所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复