With "gets new," do you mean that you are creating a new registry object?
Are you sure you are synchronized correctly? Synchronization occurs on instances, but not on variables. So if you, for example,
synchronized(roster) { roster = new Roster();
Then you only synchronized with the old, and not with the new roster
.
Thus, the following code should produce the same error:
Roster roster = new Roster(); Roster othervariable = roster; synchronized(othervariable) { roster = new Roster(); // create a new roster othervariable.wait(1000); // OK, since synchronized with this instance! roster.wait(1000); // NOT OK, not synchronized with *new* roster! }
Synchronization does not occur with the variable name, but in the content. If you overwrite the contents, you will not be re-synchronized with the new value!
source share