Using Spring threading and TaskExecutor, how do I know when a thread is finished?

后端 未结 2 1781
一个人的身影
一个人的身影 2020-12-13 05:19

Alright, possible a naive question here. I have a service that needs to log into multiple network devices, run a command on each and collect the results. For speed, rather

2条回答
  •  被撕碎了的回忆
    2020-12-13 05:35

    public List getCommandResults(String command) {
        FutureTask task = new FutureTask(new CommandTask(command))
        taskExecutor.execute(task);
    
        return task.get(); //or task.get(); return commandResults; - but it not a good practice
    }
    

提交回复
热议问题