1
我有一個Java程序,做一些實驗用的網絡:確保一個.BAT窗口關閉,完成後整個Java程序下山
javac *.java
SET nodesize=11
Set port=3001
start rmiregistry 3300 &
timeout /t 6 /nobreak > NUL
start cmd /k java Node 3300 %port% %nodesize% 0 &
timeout /t 1 /nobreak > NUL
Set /A port=%port%+1
start cmd /k java Node 3300 %port% %nodesize% 0 &
timeout /t 1 /nobreak > NUL
Set /A port=%port%+1
start cmd /k java Node 3300 %port% %nodesize% 0 &
timeout /t 1 /nobreak > NUL
和使用核磁共振檢查註冊表,以其他連接的Java程序節點,然後它應該退出。
因此,這看起來是這樣的:
public static main(){
Node n = new Node();
n.notifyOthers();//informs others that a new node has joined
n.startAlgorithm();
}
private synchronized void startAlgorithm() {
final NodeImplementation currentNode = this;
new Thread(new Runnable() {
public void run() {
try {
executeAlgorithm();
} catch (Exception e) {
e.printStackTrace();
System.exit(0)
}
}
}).start();
}
executeAlgorithm(){
while(!done){
//do a lot of stuff
//including messaging others
}
System.exit();
}
但這並不關閉控制檯窗口,任何想法如何正確地做到這一點?