Duplicate: What is the most frequent concurrency problem you’ve encountered in Java?
I've been thinking of list of common programming mistakes/pitfalls that causes the code in Java is not thread safe. Here are the common ones that I encountered in the code through the recent years of Java development.
- Using non-static fields within the singletons to hold the mutable state.
- Use of static fields to hold the mutable state and often accessing those for other classes (publi static).
- Using
javax.servlet.ServletContext
to hold mutable state as attributes. - (my No. 1, found in the code yesterday) Using system properties (
System.getProperty()
andSystem.setProperty()
) to hold mutable state and accessing it is static way in various places in the code.
Can you share your experience on this field? I know that the human imagination is nearly unbounded, so I expect lots of other creative ways to beak the code that was meant to be thread safe.
One more remark: The assumption is that there is no synchronization.