0
我使用Java ICMP ping功能ping網關。爲了執行快速ping操作,我使用ExectorService創建用於ping的線程。在ping地址之後(或不是),我想在ping之後更新Jprogressbar。我有這個代碼正在工作,但它在作業(ping線程)完成之前更新Jprogressbar。我想在作業完成後更新jprogressbar。從ExecutorService更新JProgressBar
private int NUM_THREADS = Runtime.getRuntime().availableProcessors();
ExecutorService exec = Executors.newFixedThreadPool(NUM_THREADS);
public void run() {
int JProgressBarValue = 0;
for (;GateWayKey<=GateWayKeyStop;GateWayKey++){
ip="192.168."+GateWayKey+".1";
exec.submit((new PingTask(ip,GateWayKey,true,scanFrameRefrence,ttl)));
JProgressBarValue=(GateWayKey/GateWayKeyStop)*100;
scanFrameRefrence.progressBar.setValue(JProgressBarValue);
scanFrameRefrence.progressBar.repaint();
}}