Sib*_*bbo 12 java eclipse debugging multithreading stack-trace
我有一个非常复杂的java程序,它不会终止.eclipse调试器显示一个可以挂起但没有堆栈跟踪的线程.它被称为"线程-2".
该jstack -l
线程的输出是:
"Thread-2" #17 prio=5 os_prio=0 tid=0x00007f1268002800 nid=0x3342 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
Locked ownable synchronizers:
- None
Run Code Online (Sandbox Code Playgroud)
我在Thread.start()中添加了一个断点,但我找不到一个名为"Thread-2"的线程.线程刚出现在创建两个"AWT-Event-Queue"线程之后.我不在我的程序中手动创建任何线程.
在主线程和所有其他线程退出并释放JFrame之后,以下线程仍然存在:
Thread [AWT-EventQueue-0] (Running)
Thread [Thread-2] (Running)
Thread [DestroyJavaVM] (Running)
Run Code Online (Sandbox Code Playgroud)
挂起VM时,存在以下线程:
Daemon System Thread [Signal Dispatcher] (Suspended)
Daemon System Thread [Finalizer] (Suspended)
Daemon System Thread [Reference Handler] (Suspended)
Daemon System Thread [Java2D Disposer] (Suspended)
Daemon System Thread [AWT-XAWT] (Suspended)
Thread [AWT-EventQueue-0] (Suspended)
Thread [Thread-2] (Suspended)
Thread [DestroyJavaVM] (Suspended)
Run Code Online (Sandbox Code Playgroud)
如何获取有关此线程的更多信息,或允许它终止?
编辑1:
根据Dependency Hierarchy
eclipse pom.xml
视图,我使用以下第三方库:
guava 17.0 [compile]
hamcrest-core 1.3 [test]
junit 4.11 [test]
log4j-api 2.0-beta9 [compile]
log4j-core 2.0-beta9 [compile]
Run Code Online (Sandbox Code Playgroud)
编辑2:
正如/sf/answers/2458974941/中所建议的那样,向线程类的所有构造函数添加断点,我看到Thread-0
并Thread-1
创建了log4j
但不是Thread-2
.它仍然像以前一样出现,并且在构造时没有断点触发器.
编辑3:
现在它变得令人毛骨悚然.stop()
在线程上调用时,甚至该方法都不起作用.我将其添加到/sf/answers/2458970461/中给出的代码中.至少System.exit(int)
仍然有效.但正如评论中所说,我不想使用它.
编辑4:
关于我的系统的信息:
security
,updates
并且backports
启用了repos.java version "1.7.0_91"
OpenJDK Runtime Environment (IcedTea 2.6.3) (7u91-2.6.3-0ubuntu0.15.10.1)
OpenJDK 64-Bit Server VM (build 24.91-b01, mixed mode)
编辑5:
我使用jre-8u71-linux-x64
直接从java.com下载的Java版本执行程序,但错误仍然存在.jstack -l
显示同样奇怪的线程.请注意,该程序仍然使用较旧的Java版本构建.编辑:用oracle.com的java8u72编译后,我得到了相同的行为.
编辑6:
我迭代了所有的线程字段,这是输出.我无法从这些字段中获得任何提示,该线程甚至没有目标.
name: [C@6b67034
priority: 5
threadQ: null
eetop: 140274638530560
single_step: false
daemon: false
stillborn: false
target: null
group: java.lang.ThreadGroup[name=main,maxpri=10]
contextClassLoader: null
inheritedAccessControlContext: java.security.AccessControlContext@0
threadInitNumber: 3
threadLocals: null
inheritableThreadLocals: null
stackSize: 0
nativeParkEventPointer: 0
tid: 17
threadSeqNumber: 20
threadStatus: 5
parkBlocker: null
blocker: null
blockerLock: java.lang.Object@16267862
MIN_PRIORITY: 1
NORM_PRIORITY: 5
MAX_PRIORITY: 10
EMPTY_STACK_TRACE: [Ljava.lang.StackTraceElement;@453da22c
SUBCLASS_IMPLEMENTATION_PERMISSION: ("java.lang.RuntimePermission" "enableContextClassLoaderOverride")
uncaughtExceptionHandler: null
defaultUncaughtExceptionHandler: null
threadLocalRandomSeed: 0
threadLocalRandomProbe: 0
threadLocalRandomSecondarySeed: 0
Run Code Online (Sandbox Code Playgroud)
编辑7:
增加了一个观察点到name
的领域Thread
.它只能通过我的分析代码访问,似乎从未编写过......
编辑8:
jstack
-F -m为我的程序抛出一个错误:
Attaching to process ID 10973, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.71-b15
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.tools.jstack.JStack.runJStackTool(JStack.java:140)
at sun.tools.jstack.JStack.main(JStack.java:106)
Caused by: java.lang.RuntimeException: Unable to deduce type of thread from address 0x00007ff68000c000 (expected type JavaThread, CompilerThread, ServiceThread, JvmtiAgentThread, or SurrogateLockerThread)
at sun.jvm.hotspot.runtime.Threads.createJavaThreadWrapper(Threads.java:169)
at sun.jvm.hotspot.runtime.Threads.first(Threads.java:153)
at sun.jvm.hotspot.tools.PStack.initJFrameCache(PStack.java:200)
at sun.jvm.hotspot.tools.PStack.run(PStack.java:71)
at sun.jvm.hotspot.tools.PStack.run(PStack.java:58)
at sun.jvm.hotspot.tools.PStack.run(PStack.java:53)
at sun.jvm.hotspot.tools.JStack.run(JStack.java:66)
at sun.jvm.hotspot.tools.Tool.startInternal(Tool.java:260)
at sun.jvm.hotspot.tools.Tool.start(Tool.java:223)
at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
at sun.jvm.hotspot.tools.JStack.main(JStack.java:92)
... 6 more
Caused by: sun.jvm.hotspot.types.WrongTypeException: No suitable match for type of address 0x00007ff68000c000
at sun.jvm.hotspot.runtime.InstanceConstructor.newWrongTypeException(InstanceConstructor.java:62)
at sun.jvm.hotspot.runtime.VirtualConstructor.instantiateWrapperFor(VirtualConstructor.java:80)
at sun.jvm.hotspot.runtime.Threads.createJavaThreadWrapper(Threads.java:165)
... 16 more
Run Code Online (Sandbox Code Playgroud)
奇怪线程的类名是java.lang.Thread
.
我不使用任何命令行参数来执行程序.添加-Dlog4j2.disable.jmx=true
选项会为奇怪的线程提供名称Thread-1
.
我更新log4j
到2.5,Thread-0
当-Dlog4j2.disable.jmx=true
给出选项时,奇怪的线程现在有名称,而Thread-1
当它没有时.
编辑9:
完全删除了log4j,错误仍然存在.现在调用该线程Thread-0
.
这是项目,如果有帮助的话.
不确定这对您来说是否足够,但以下代码将允许您通过其名称尝试interrupt
任何内容:Thread
//Set of current Threads
Set<Thread> setOfThread = Thread.getAllStackTraces().keySet();
//Iterate over set to find yours
for(Thread thread : setOfThread){
if (thread.getName().equals("Thread-2")) {
thread.interrupt();
break;
}
}
Run Code Online (Sandbox Code Playgroud)
另外,请查看 JavaSpecialists 的这篇文章Thread
,该文章尝试根据 Thread 的构造函数调用安全管理器这一事实来识别 Thread 的创建者。如果我们向系统添加自定义SecurityManager
,我们可以跟踪线程的发起者。
归档时间: |
|
查看次数: |
1022 次 |
最近记录: |