简体   繁体   English

奇怪的行为在循环中重新运行Java应用程序

[英]Strange behavior re-runing java application in a loop

Unix daemon runs a script a loop, the script calls a java program: java {java_args} myClas.jar Unix守护程序循环运行一个脚本,该脚本调用一个Java程序:java {java_args} myClas.jar

The java program is heavy program with multiple threads. Java程序是具有多个线程的繁重程序。

The problem is very strange: First execution works as expected. 问题很奇怪:第一次执行按预期工作。 But the second execution is stuck some where and I can't find a reason (very hard to debug this). 但是第二次执行被卡在某些地方,我找不到原因(很难调试)。

Is there a possibility that when first execution is finished there are still not-cleaned resources or threads left from this execution? 是否有可能在第一次执行完成后仍然有未清理的资源或该执行留下的线程?

If yes, is it possible to clean and kill everything right after process completes? 如果是,是否可以在过程完成后立即清理并杀死所有内容?

If by resources, you mean threads, then no. 如果用资源来表示线程,则不行。 When the VM shuts down, everything on the heap, all threads, objects and monitors are disposed of. 当VM关闭时,堆中的所有内容,所有线程,对象和监视器都将被丢弃。 However if you're depending on the existence/absence of a file for locking or something similar, a deadlock is possible. 但是,如果您依赖于文件的存在/不存在进行锁定或类似操作,则可能发生死锁。 Also, is it possible that the first process is still running when you launch the second one? 另外,启动第二个进程时,第一个进程是否仍在运行?

If your java process is stuck on the second run, you can attach jvisualvm to it and should be able to figure out where it's stuck. 如果您的Java进程在第二次运行中卡住,则可以将jvisualvm附加到它上,并且应该能够确定它的卡住位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM