How to identify sections of code executed by multiple threads-Collection of common programming errors

In general, it is not possible to do statically, i.e. by inspection of the code. (The problem is undecidable due to the halting problem.)

Your only option is to do the analysis runtime, that is, to log which actual thread executes with method. You have a few options. Here are two that I come to think of immediately.

  • Add System.out.println(Thread.currentThread()) on interesting methods
  • Use for example AspectJ to do something similar.