ScheduledExecutorService - 检查任务是否已按相同时间安排

时间:2016-06-29 11:36:21

标签: java multithreading scheduledexecutorservice

我有两个任务,每天安排两次,时间不同。

  

示例:

     
      
  1. Task1计划于上午11点和下午3点
  2.   
  3. 任务2计划于下午2点和下午5点
  4.   

我想检查任务是否已经安排在同一时间?

ScheduledExecutorService executor1 = Executors.newScheduledThreadPool(MYTHREADS);

        String[] hostList = { "http://crunchify.com","http://yahoo.com"}; //Two Tasks
        String[] timings = {"11:0,15:0","10:0,17:0"}; //(11AM,3PM) and (10AM,5PM) scheduled timings twice a day

        for (int i = 0; i < hostList.length; i++) {
            String url = hostList[i];           
            Runnable worker = new MyRunnable(url);
            String[] schedulingHour = timings[i].split(",");            
            for(int j=0;j<schedulingHour.length;j++){
                executor1.schedule(worker,getTimeUntilTarget(Integer.parseInt(schedulingHour[j].split(":")[0]),Integer.parseInt(schedulingHour[j].split(":")[1])), TimeUnit.MILLISECONDS);
            }               

        }

0 个答案:

没有答案