I’m updating an old project, and I’m wondering whether I should remove some objects marked as “obsolete” in the IDE. The objects in question are Vector and Hashtable. I’ve done some research, and it seems that the newer counterparts of these objects – ArrayList and HashMap – are basically the same, just not synchonized.
My question is, why should I make the switch? Aren’t I just taking away a bit of security from my application in exchange for a small amount of speed? Seems like it’s not a monumental decision either way, but I thought I’d see if it was worth the time before making a decision.
Thanks!
If your sole threading security is relying on the synchronization of
VectorandHashtable, you’re almost certainly in trouble.Usually, coarser-grained operations need to be synchronized – the “synchronize each small operation on the collections and hope that’s good enough” approach is almost never what’s required, so why take the small hit of having it at all?
If you’re sharing mutable data (such as collections) between threads, you need to consider how to do so carefully – using
VectorandHashtablecan give you a false sense of security.