您的位置:首页 > 编程语言 > Java开发

线上Java系统的调试经验一则

2010-11-17 21:09 162 查看
当系统已经上线,如果出现任何问题如何调试呢?正在运行的系统是不可能加入debug的参数的,一旦停止就会造成当前的数据破坏,也无从查找问题。

以Linux环境为例,如果直接是在命令行运行程序的,直接按Ctrl+\ 就可以看到了,如果是后台运行的,输入Kill -3 PID ,然后到输出的标准日志里面就会有。

非常不错的功能,当时发现有问题就可以多了一种有效的方式去发现问题,再也不用重新开一个debug模式运行的应用,直到等问题重现才知道什么情况,汗~~~。如果有兴趣就深入看一下thread dump的东西。

最后补充一下,mbean的方式也可以,有空研究一下。

原文:

Run the program from the command prompt and when the CPU peaks take a thread dump. You can get a thread dump by pressing the following at the command prompt: Ctrl+\ for unices or Ctrl+Break for windows machines. If you are running your application as a back ground process in unix, you could execute DE>kill -SIGQUIT <pid>DE> from another command prompt. The above signals the VM to generate a full thread dump. Sun’s VM prints the dump on the error stream while IBM’s JDK generates a new file with the thread dump every time you send the signal.

参考文献:

http://www.0xcafefeed.com/2004/06/of-thread-dumps-and-stack-traces/

http://lzmhehe.javaeye.com/blog/335526
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: