javaexit(0)_java中的System.exit(0)

I am writing an application program using swing. I need to exit from the application by clicking the JButton for that can i use System.exit() or should i use some other methods, which is the best practice. If calling System.exit() is not best practice then tell the reason and tell the alternative way to exit from the application.

解决方案

Personnaly, I do consider as best practice to let application exit by itself : if you write a main class with a main(String[] args), with empty code, running it will exit silently from Java program.

But, in most times, like most of developpers, I rely upon System.exit(/an exit code/), especially for Swing applications, where the Swing EDT will run endlessly, as justkt wrote.. The known drawxback of this method is that most of applciation code is not called, what I avoid by setting a shutdown hook by calling Runtime.addShutdownHook(Thread), which will allow me to clean application (close threads, and so on).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值