KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Possible Duplicate: Thread safety in Java class I'm reading Java concurrency in Practice , and I've come to an example that puzzles me. The authors state that this class is not threadsafe public class MutableInteger { private int number; public int getInt() { return number; } public void setInt(int val) { number = val; } } And they also state that synchronizing only one method (the setter for example) would not do; you have to syncronize both. My question is: Why? Wouldn't synchronizing the setter just do?
Tags (comma-separated)
Save Edits
Cancel