我目前有一个程序,它在后台运行多个线程。应将所有输出数据传递给单个线程,然后处理,显示并连续追加到文件。我一直在传递空值,并且无法弄明白为什么。
我试图从doInBackground()方法传递一个字符串,我也尝试发布结果
//Code to initialize threads
new Thread(new ProcessOutputs()).start();
ExecutorService pool = Executors.newFixedThreadPool(3);
Set<String> deviceSet = PingUtilityMain.devices.keySet();
Iterator<String> it = deviceSet.iterator();
while(it.hasNext()){
PingShip callPing;
try {
callPing = new PingShip(PingUtilityMain.devices.get(it.next()));
Future future = pool.submit(callPing);
pingOutputs.add(future);
} catch (Exception e) {
System.out.println("Executor Error");
}
}
//
//
//
public class PingShip extends SwingWorker<String, String>{
protected String doInBackground(){
//task
//publish(outputString);
return outputString;
}
//
//
//
public class ProcessOutputs extends SingWorker<Void, Void>{
protected Void doInBackground(){
Future<String> pingOutput = PingUtility.pingOutputs.get(0); //This is the first value of an arraylist containing all outputs
String output = pingOutput.get();
//Task
PingUtility.pingOutputs.remove(0);
}
}