1

为什么我的应用程序抛出java.lang.ArrayIndexOutOfBoundsException:-1的Future.get()多线程

java.lang.ArrayIndexOutOfBoundsException:-1

当调用的Future.get

( )关于java.utils.concurrent.Future ??

List<Future> tableLoadings = new LinkedList<>(); 
    ExecutorService executor = Executors.newFixedThreadPool(8); 
    try{ 
     for(Entry<Integer, String> entry: farmIds.entrySet()) 
     { 
      int id = entry.getKey(); 
      String username = entry.getValue(); 

      psLog.println("START ELABORAZIONE FARMACIA ID : "+ id+" TPH_USERNAME : "+username);  
      /*SdajSdaj*/ 
      tableLoadings.add(executor.submit(new StatusMultiThreading(id, username, psLog, connSTORY, connCF, mongoDatabase))); 
     } 
     for (Future<Void> future : tableLoadings) {   
       try{ 
        future.get();   
       }catch(Exception e){ 
        psLog.println("[EE] ERORE ELABORAZIONE THREAD FARMACIA [EE] "+e.getMessage()); 
       } 
     } 
    }finally{ 
     executor.shutdown(); 
     psLog.println("END CONSOLIDA STATUS FARMACIE"); 
    }   

这是日志..

START ELABORAZIONE FARMACIA ID : 62 TPH_USERNAME : A0102987 
START ELABORAZIONE FARMACIA ID : 63 TPH_USERNAME : A0103019 
START SENDING DATA TO DB FARMID = 66 
... 
START SENDING DATA TO DB FARMID = 17 
[EE] ERORE ELABORAZIONE THREAD FARMACIA [EE] java.lang.ArrayIndexOutOfBoundsException: -1 
[EE] ERRORE ELABORAZIONE THREAD FARMACIA [EE] java.lang.ArrayIndexOutOfBoundsException: -1 
END CONSOLIDA STATUS FARMACIE 

Ø无法找到没有错,如果我调试。

我不能进去.get()方法,所以我不明白这行代码是无效的。

+0

在级联异常的可能情况下,使用e.printStackTrace()(或更好的记录)来了解错误的原因。 – tucuxi

回答

0

什么可至今说:你使用的ExecutorService的任务传递:

new StatusMultiThreading(id, username, psLog, connSTORY, connCF, mongoDatabase) 

后来,当你调用get()相应的任务被触发。所以这个例外发生在你的这一类内部。

+0

可能是错误在这里: \t \t [...]'List results = List.class.cast(payload.get(“result”)); \t \t \t \t results.remove(0); \t \t results.remove(0); \t \t results.remove(results.size() - 1); \t \t results.remove(results.size() - 1); '[...] –

+0

好,非常感谢 –

相关问题