可能重複:
Java: How could I 「intercept」 Ctrl+C in a CLI application?無法趕上中斷在java命令行程序
在Windows上我啓動Java非GUI應用程序執行任務的 然後按CNTL-C和程序只是退出,我的中斷處理代碼似乎沒有觸發,即使在主要方法中放入try/catch,也不會顯示堆棧跟蹤以表明它已被中斷。
public static void main(final String[] args) throws Exception
{
try
{
CmdLineDecoder cld = new CmdLineDecoder();
cld.start(args);
System.exit(0);
}
catch(Exception e)
{
e.printStackTrace();
throw e;
}
}
我明顯誤解了Cntl-C的影響,但是什麼?
CmdLineDecoder.start是否引發了InterruptedException? – Jeffrey
但是......什麼?你的意思是這樣關閉嗎? – Gray
http://stackoverflow.com/questions/1216172/java-how-could-i-intercept-ctrlc-in-a-cli-application – jtoberon