2016-12-13 9 views
0

送信中にスレッドプールがタスクを拒否しました。スレッドプールのサイズは固定されており、それは8です。私は8以上のタスクをうんざりしていませんが、それは拒否しています。私は、ブロックキューを使用してみましたが、それは私を助けていません。スレッドプールを使用してタスクを実行しているときにRejectedExecutionExceptionが発生しました。JAVA

はここ

try { 
      List<Future> tasks = new ArrayList<Future>(); 
      ThreadPoolExecutor tpe = (ThreadPoolExecutor) Executors.newFixedThreadPool(10); 
      Process process = new Process(); 
      ProcessingJobMeta meta = process.getPJM(); 
      List<CuratedInput> cil = meta.getCuratedInputList(); 
      for (final CuratedInput ci : cil) { 
       for (final Preperation prep : Preperation.values()) { 
        for (final Export export : Export.values()) { 
         Runnable runnable = new Runnable() { 
          public void run() { 
           LOGGER.info("Executing.................." + prep.toString()); 
           LOGGER.info("Executing.................." + export.toString()); 
           PreperationFactory.getPreperation(prep.toString(), ci); 
           ExportFactory.getExport(export.toString(), ci); 
          } 
         }; 
//      tpe.submit(runnable); 
         tasks.add((Future) tpe.submit(runnable)); 

         for (Future p : tasks) { 
          LOGGER.info("---------------inside the futures for loop------------"); 
          LOGGER.info("Result of the future executed ------> " + p.get()); 
         } 

         tpe.shutdown(); 

         while (!tpe.isShutdown()) { 

         } 
        } 
       } 

      } 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

答えて

1

あなたの問題は、あなたがループ内のプールをシャットダウンし、すでにシャットダウン・プールに多くのスレッドを追加することattemtingということで、私のコードスニペットです。試してみてくださいこの

List<Future> tasks = new ArrayList<Future>(); 
     ThreadPoolExecutor tpe = (ThreadPoolExecutor) Executors.newFixedThreadPool(10); 
     Process process = new Process(); 
     ProcessingJobMeta meta = process.getPJM(); 
     List<CuratedInput> cil = meta.getCuratedInputList(); 
     for (final CuratedInput ci : cil) { 
      ..... 
     } 

     tpe.shutdown(); 
     while (!tpe.isShutdown()) { 

     } 

よう

tpe.shutdown(); 

while (!tpe.isShutdown()) { 

} 

何かループの外にこれらの行を置くこと

関連する問題