有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JAVAlang.ArrayIndexOutofBounds异常:1未来。get()多线程

为什么我的应用程序会抛出错误

java.lang.ArrayIndexOutOfBoundsException: -1

当我召唤未来。java上的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

如果我调试,我找不到任何错误

我不能进去。get()方法,所以我不知道哪行代码是无效的


共 (1) 个答案

  1. # 1 楼答案

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

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

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