English 中文(简体)
如何发现谁在java制造read子?
原标题:how to find out who create a thread in java?

如果网络浏览确实停止了任何一种 da门的透镜,那么tom不可能通过关闭而关闭。 sh

例如:

public class demo implements ServletContextListener{

  public void contextDestroyed(ServletContextEvent arg0) {
    // TODO Auto-generated method stub
    // yes,we can cancel timer in here,but this is not the major problem
   }

  public void contextInitialized(ServletContextEvent arg0) {        
    Timer timer = new Timer();
    timer.schedule(new Test(), 1000, 1000*10);
    }
}

public class Test extends TimerTask{  
@Override
public void run() {
    System.out.println("AAAA");        
   }
}

like as above,tomcat can not be shutdown by shutdown.sh. from jvisualvm,threads inspector say:

"Timer-0" - Thread t@40
   java.lang.Thread.State: TIMED_WAITING
    at java.lang.Object.wait(Native Method)
    - waiting on <3957edeb> (a java.util.TaskQueue)
    at java.util.TimerThread.mainLoop(Timer.java:552)
    at java.util.TimerThread.run(Timer.java:505)

   Locked ownable synchronizers:
    - None

stack info did not point out which java class created the thread, my question is how to find out who created the thread from many webapps.

感谢!

最佳回答

以下是从最快/最可靠到最缓慢/最困难的角度来看待的办法清单:

  1. 如果您的产物是该种的产物,则在构造中造成一种例外(实际上没有扔掉)。 当你需要知道什么时候才制作透镜时,你可以简单地检查或印刷。

  2. 如果你没有来源,那么read子就可以成为创造这种来源的良好 h。

  3. 如果称呼一般服务(如java.util)。 时间,然后,你可以在电离层电离层中设定一个有条件的断点。 条件应当是直截了当的名称;如果有人用这个名字制造了read子,那么 de就会停止。

  4. 如果你没有太多的透镜,就会在<代码>Thread/code>的构造中设定一个突破点。

  5. If you have many threads, attach a debugger to the app and freeze it. Then examine the stack traces.

  6. If everything else fails, get the source code for the Java runtime and add logging code in the classes you want to observe, compile a new rt.jar and replace the original one with your version. Don t try this in production, please.

  7. 如果资金问题不成问题,你可以使用动态追踪工具,例如Compuware APM,或者,如果你重新使用关于短链氯化石蜡或太阳能,则你可分别尝试

问题回答

你们还可以写出一只小 j Instrument仪器,以包涵 construct子(和堆放场),而不是试图修 mo。

如果你控制了那类,那么当制造时,你就能够追捕 trace:

public class Test extends TimerTask {
  final StackTraceElement[] callerStack;

  public Test () {
    callerStack = Thread.currentThread().getStackTrace();
  }

  @Override
  public void run() {
    System.out.println("AAAA");
    System.out.println("Creator: "+Arrays.asList(callerStack));
  }

  @Override
  public String toString () {
    return "Test created by "+Arrays.asList(callerStack);
  }
}

可以使用Byteman查找从哪里开始透镜。

这里是一个基于视窗的幻灯塔,可以得出一个想法。 必须使用Beteman的<条码>栏选项,并设置<条码>org.jboss.byteman.transform.all/code>。

set BYTEMAN_HOME=C:	oolsyteman-download-4.0.22
set BYTEMAN=%BYTEMAN_HOME%libyteman.jar
set JAVA_TOOL_OPTIONS="-javaagent:%BYTEMAN%=script:appmain.btm,boot:%BYTEMAN%"
java -Dorg.jboss.byteman.transform.all -jar whatever...

创建<条码>。

RULE trace thread start
CLASS java.lang.Thread
METHOD start
IF true
DO traceStack("*** found the caller for " + $0.getName() + "
", 10)
ENDRULE

一旦您提出申请,你就应当能够看到这样的东西。

*** found the caller for pool-3-thread-1
java.lang.Thread.start(Thread.java:-1)
java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:957)
java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1367)
java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
...

应当有一套用户代码,以进一步缩小标记。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...