How to identify code sections executed by multiple threads

I use net beans for Java development. Am I working on a multi-threaded application and I want to easily identify sections of code that are executed by more than one thread? Is there an easy way to do this?

For example, if any field of a method of class ABC is executed by more than one thread?

+3
source share
2 answers

This is something that can only be determined at runtime.

You can cast this method before calling the method to determine the calling thread.

public static void reportThread(String methodName) {
    //Somehow LOG (println, logging framework)
    LOG(methodName + " was ran on thread: " + Thread.currentThread().getName());

}
+2
source

In general, it is statically impossible, that is, to check the code. (The problem is unsolvable due to the stopping problem.)

- , , . . , .

  • System.out.println(Thread.currentThread())
  • , , AspectJ, - .
+2

Source: https://habr.com/ru/post/1751405/


All Articles