如何在Java应用程序中调试静默失败? [英] How do I debug silent failures in Java applications?

查看:140
本文介绍了如何在Java应用程序中调试静默失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图调试我的Java应用程序中没有错误的问题,也没有例外,甚至不会崩溃应用程序(似乎在单独的线程中发生故障)。



问题似乎在调用库函数(它是 JAXBContext.newInstance(String)如果这很重要)。该程序将在通话之前到达线路,但不会在之后。我的 catch 块没有输入,程序只是继续运行。



尝试渲染时出现问题对通过Struts进行的Web请求的XML响应。请求已被处理,代码应该对响应对象进行编组。客户端立即获得响应(因此代码似乎不会挂起一个循环),但它只是空的。



我已经设置了一个断点有问题的行,但调试器只是运行它,我没有一个线索为什么。



我正在使用eclipse,应用程序运行在OSGi容器(Apache Felix)这是以 -Xdebug -Xrunjdwp:transport = dt_socket,address = 8000,server = y,suspend = y 开始的。在Eclipse中,然后使用远程Java应用程序的调试设置连接调试器。



有什么技巧可以解决这个问题? b $ b

解决方案

可能是一个明显的问题,但你确定你在捕捉Throwable吗?一个未经检查的异常很容易导致有问题的线程死机(假设在调用堆栈中没有任何一个可以捕获它。)



由于您暂停虚拟机启动您的调试参数,我假设您已经确认调试器正确附加。事实上,你说调试器正好跳过通话是非常可疑的。您可以在此应用程序中点击任何断点吗?在这个班上呢?在这个线程中怎么样?



没有调试器,你如何缩小相关行? println / debug to a file?



你可以粘贴有问题的方法的代码片段吗?



你可以通过在问题发生之前创建第二个线程来确认线程正在死亡的原理,并将其加入到您认为正在死亡的线程中。那么当有问题的线程退出时,第二个线程的run()方法将被调用,并且你会知道它已经死了(但仍然不知道为什么)。



回答你的一般问题,当我有一个Java应用程序中的错误,我无法在调试器中重现(由于各种原因而不时发生),我会逐渐修改我的代码,使用sysout printlns或输出到文件。如有必要,我还可以修改我的代码正在调用的代码。如果您没有调用代码的源代码,可以尝试许多BCI框架之一,将您的字节码注入到有问题的方法中。这是一个乏味的过程,但只会偶尔发生。


I'm trying to debug a problem in my Java application that throws no errors, no exceptions and doesn't even crash the app (it seems the failure happens in a separate thread).

The problem seems to be inside a call to a library function (it's JAXBContext.newInstance(String) if that matters). The program will reach the line just before the call, but not the one just after it. My catch blocks are not entered and the program just continues to run.

The problem happens while trying to render an XML response to a web request that came in via Struts. The request has been handled and the code should marshal the response object. The client gets a response right away (so the code doesn't seem to hang in a loop), but it's just empty.

I have set a breakpoint just before the problematic line but the debugger just runs over it, I haven't a clue why.

I'm using eclipse and the application runs inside an OSGi container (Apache Felix) that was started with -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y. From within Eclipse I then use the Debug settings for "Remote Java application" to connect the debugger.

What are techniques to get at such a problem?

解决方案

Probably an obvious question, but are you sure you are catching Throwable? An unchecked exception could easily cause the thread in question to die (assuming no one above you in the call stack is catching it either.)

Since you are suspending the VM on startup with your debug arguments, I assume you have confirmed that the debugger is attaching correctly. The fact that you say the debugger skips right past the call is very suspect. Are you able to hit any breakpoints in this application? What about in this Class? What about in this thread?

How did you narrow down the line in question without the debugger? println/debugging to a file?

Can you paste a code snippet of the method in question?

You could confirm the theory that the thread is dying by creating a second thread before the problem occurs and joining it to the thread you think is dying. Then the second thread's run() method would be invoked when the thread in question exits, and you'd know it died (but would still not know why.)

In answer to your general question, when I have a bug in a Java app that I can't reproduce in the debugger (which happens from time to time for various reasons), I incrementally modify my code with sysout printlns or output to files. If necessary, I may also modify the code my code is invoking. If you don't have the source code to the code you are invoking, you can try one of the many BCI frameworks to inject your byte code into the methods in question. It's a tedious process, but only happens occasionally.

这篇关于如何在Java应用程序中调试静默失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆