There is a rule to find out, for sure, all objects that could possibly have concurrent access in a Java program? My intention is use such rule, if it exists, to find out which Java classes could possibly have concurrent access and then guarantee that they are thread-safe. This rule could be very useful when inspecting a large Java project. I’ve thought to look for static methods, but I’m not sure if this is the only way an object can be accessible to multiple threads.
Share
It seems very, very unlikely that such a thing exists as a single rule. Imagine the following:
I don’t know about you, but I can’t really contrive a rule that isn’t equivalent to deciding the halting problem here, especially not by simple inspection of types or declarations. I think you may find that like other static analysis techniques, there are a set of properties that you can check within reason. The Bandera project appears to be an effort to use various model-checking techniques to verify properties of concurrent Java code. There may be other similar efforts (all of which are most likely to involve model checking, given the presence of concurrency).