AttachingConnector socketAttachingConnector = null;
6 /*
7 * host and port should be set here
8 */
9.
10 try{
11 vm = socketAttachingConnector.attach(arguments);
12 }catch(Exception e){
13 e.printStackTrace();
14 }
15 return this.vm;
16 }
JVM TI学习(1) 如何中断weblogic中stuck thread(2)
时间:2010-12-26 BlogJava 走走停停又三年
有了线程名、connection,我们就可以用下面的方法去中断挂死线程了,
1 public void terminateThread(String threadPattern){
2 if(vm != null){
3 List threads = vm.allThreads();
4 ThreadReference tr = null;
5 int loop = -1;
6 for(loop=0; loop<threads.size(); loop++){
7 if(tr.toString().indexOf(threadPattern) != -1){
8 tr.interrupt();
9 System.out.println(threadPattern + " is terminated!");
10 break;
11 }
12 }
13 if(loop == threads.size())
14 System.out.println("no matched thread was found in target VM!");
15 }
16 }
线程被中断的时候,会收到InterruptedExcetpion,比如我在测试中让线程sleep,然后利用上面的程序去中断sleep,收到的异常如下:
java.lang.InterruptedException: sleep interrupted
at java.lang.Thread.sleep(Native Method)
at test.jpda.clazz.Test2.run(Test2.java:14)
at test.jpda.clazz.Test1.run(Test1.java:10)
at test.jpda.clazz.Test.run(Test.java:9)
at jsp_servlet.__index._jspService(__index.java:91)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.ru(WebAppServletContext.java:3498)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(E
|