How to stop uninterruptible threads in Java

后端 未结 6 1974
有刺的猬
有刺的猬 2020-12-06 14:52

I have a Java application that I CAN\'T EDIT that starts a java.lang.Thread that has this run() method:

p         


        
6条回答
  •  孤街浪徒
    2020-12-06 15:47

    The java debugger will allow you to kill a thread by injecting an exception into it.

    Start your Java process and have it listen on some port:

    java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=4444 
    

    and connect the debugger with something like:

    jdb -attach 127.0.0.1:4444
    

    and issue the following command:

    threads
    

    to get a list of the running threads, and use the kill command to kill a running thread.

    kill 0xe2e new java.lang.IllegalArgumentException("er");
    

提交回复
热议问题