java.lang.ArrayIndexOutOfBoundsException:-1 future.get()multithreading

时间:2017-04-26 09:37:51

标签: java multithreading indexoutofboundsexception java.util.concurrent

为什么我的应用会抛出

  

java.lang.ArrayIndexOutOfBoundsException:-1

当我在java.utils.concurrent.Future上调用future.get()时

   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

如果我调试,O不会发现任何错误。

我无法进入.get()方法,所以我不明白哪一行代码无效。

1 个答案:

答案 0 :(得分:2)

到目前为止可以说:您使用ExecutorService传递任务:

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

稍后,当您致电get()时,会触发相应的任务。所以异常发生在你的那个类中。