> > Are the elements synchronized
>
> What do you mean?
>
> or the collection?
>
> Sure. The collection is synchronized.
Just trying to understand the context of your question. I didn't know what you meant by the elements are synchronized? Also don't know what you mean by issues? What are you attempting to do with it?
> mean by issues? What are you attempting to do with
> it?
Just trying to raise a little discussion about all the ways you could still have threading issues
> question. I didn't know what you meant by the
> elements are synchronized? Also don't know what you
no elements aren't synchronized. Just the collection
Sure, there are lots of ways you could have threading problems. Even with simple code likeif (!collection.contains(thing)) {
collection.add(thing);
}
it isn't sufficient to synchronize the call to contains() and the call to add() separately. Which is what you are doing.
> only if the elemnts added are not immutable?
> synchronized is a lil different from thread safe I
> guess.
Even if you had immutable objects you could still have issues
consider the equals method. First off, equals is defined in Object as not synchonized, so your equals method probably isn't synchronized. BUT even if it was, or even if you synchronized on it. But then the list you're comparing to might change, so you synchronize on that... even then you could STILL have thread race conditions if that other list wasn't synchronized
... Or you could just make your own collection where the underlying data structure is a public member variable :)
> > only if the elemnts added are not immutable?
> > synchronized is a lil different from thread safe I
> > guess.
>
> Even if you had immutable objects you could still
> have issues
>
> consider the equals method. First off, equals is
> defined in Object as not synchonized, so your equals
> method probably isn't synchronized.
well neither is hashcode, but they dont change the state of the object, plus for immutable objects you cant even have the state changed so how can it be an issue, please explain.
What I'm saying is that even if you try to make your list as threadsafe as possible, there is no way to make equals totally threadsafe because things could be changing with the object you are comparing to. Not only that, but the other object would have to be totally synchronized aroujnd its data AND synchronize on the list being compared to in equals to stand a chance of total thread safety.
My head hearts. I'm going to get a beer.
> What I'm saying is that even if you try to make your
> list as threadsafe as possible, there is no way to
> make equals totally threadsafe because things could
> be changing with the object you are comparing to. Not
Not if the object is immutable.
>
> My head hearts. I'm going to get a beer.