有没有办法在 Oracle 异常上触发 jvm 线程转储?
我们有一个在 Websphere 中运行的 Java 程序,并使用直接使用 jdbc 的 Oracle 数据库(没有 Hibernate 或 JPA)。我们的客户正在使用 HP Performance Center 进行负载测试,他在负载下偶尔会遇到 Oracle“死锁”异常
Caused by: java.sql.SQLException: ORA-00060: deadlock detected while waiting for resource
有没有办法在代码中或外部强制进行与 kill 时得到的相同类型的线程转储-3
jvm何时发生此异常?
We've got a Java program that runs in Websphere, and uses an Oracle database using straight jdbc (no Hibernate or JPA). Our customer is doing load testing using HP Performance Center, and he's getting occasional Oracle "deadlock" exceptions under load
Caused by: java.sql.SQLException: ORA-00060: deadlock detected while waiting for resource
Is there a way to, either in the code or externally, force the same sort of thread dump you get when you kill -3
the jvm when this exception happens?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您无法自动检测异常发生的时间,那么了解如何枚举线程将没有多大用处。
我们一直这样做。我们基本上使用:
当我们的应用程序启动时,然后在发生异常时转储我们想要的信息:
Map; mst = Thread.getAllStackTraces();
Runtime.getRuntime().freeMemory()
/maxMemory()
/totalMemory()< /code> 获取基本内存信息
用户使用模式(如果用户可以与之交互的应用)
house -made "analytics"
etc.
然后你可以调用很多其他东西并变得更有趣。例如,我们自动将崩溃报告(包括完整的堆栈跟踪)发送到等待此类跟踪的服务器。
Knowing how to enumerate threads won't be of much use if you can't detect automatically when the exception happens.
We do this all the time. We're basically using:
when our app starts up and then we dump the infos we want when an exception occurs:
Map<Thread, StackTraceElement[]> mst = Thread.getAllStackTraces();
Runtime.getRuntime().freeMemory()
/maxMemory()
/totalMemory()
to get basic memory infosuser usage pattern if it's an app the user can interact with
house-made "analytics"
etc.
You can then call a lot of other things and get fancy. For example we're automatically sending crash reports (including the full stack trace) to a server waiting for such traces.
对于当前线程,可以使用 Thread.dumpStack()。
对于所有线程,您可以使用 Thread.enumerate() 获取所有正在运行的线程并 dumpStack() 每个线程,或者您可以使用 Thread.getAllStackTraces()并将它们打印到控制台或任何您需要的地方。
要在发生这些异常时实现此目的,如果您无法在自己的代码中执行此操作,您可以尝试 AOP,编写代理(如果您使用的是 Java 6+),或者您可以在紧要关头获取源代码SQLException 的代码,将其更改为在其构造函数中转储堆栈,重新编译并将此类放回引导类路径中,然后再进行其他操作。
For the current thread, you can use Thread.dumpStack().
For all threads, you can either use Thread.enumerate() to get all running threads and dumpStack() each of them or you can use Thread.getAllStackTraces() and print those out to the console or wherever you need to.
To get this to happen when these exceptions occur, if you can't do this in your own code, you could try AOP, writing an agent (if you are using Java 6+) or you could, in a pinch, grab the source code of SQLException, change it to dump the stack in its constructor, recompile and put this class back in the boot class path before everything else.