Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to identify sections of code executed by multiple threads

I'm using net beans for Java development. I'm working on a multi threading application and I want to easily identify code sections which are executed by more than one thread? Is there a easy way to do that?

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

like image 811
user318247 Avatar asked Jul 03 '26 08:07

user318247


1 Answers

This is something that can only be determined at runtime.

You can throw this method to the beginning you your method calls 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());

}
like image 121
jjnguy Avatar answered Jul 05 '26 20:07

jjnguy