| Author |
Collections.synchronizedMap or thread safe classes in collection which one is better?
|
Tanu Gulati
Ranch Hand
Joined: Oct 06, 2008
Posts: 113
|
|
Map myMap = Collections.synchronizedMap (myMap);
synchronizes the operations on myMap collection class my question is if i have synchronize any way then why i should not be using Hashtable ? is Collections.synchronizedMap provide some extra functionality
|
thanks
Tanu Gulati
|
 |
cherry ch
Greenhorn
Joined: Nov 24, 2009
Posts: 1
|
|
|
I think HashTable and Vector is not a good idea
|
 |
Tanu Gulati
Ranch Hand
Joined: Oct 06, 2008
Posts: 113
|
|
|
i have also been told that Hashtable and Vector make your Operation slow and but would not Collections.synchronizedMap be making your operations on map slow? my question is more towards what is the advantages developers see in using Collections.synchronizedMap than to use Hashtable.
|
 |
Ireneusz Kordal
Ranch Hand
Joined: Jun 21, 2008
Posts: 423
|
|
Tanu Gulati wrote: my question is more towards what is the advantages developers see in using Collections.synchronizedMap than to use Hashtable.
using Collections.synchronizedMap you may very quick and easy make any map thread save.
Any map - even a map returned from old libraries you use, but you don't have access to their source code.
|
 |
Rok Ć telcer
Ranch Hand
Joined: Nov 03, 2009
Posts: 101
|
|
Hi,
Vector & Hashtable are both leftovers (legacy) from 1.0 API and still available only due to the compatibility reasons ...
cherry ch wrote:
I have also been told that Hashtable and Vector make your Operation slow and but would not Collections.synchronizedMap be making your operations on map slow?
In general the above statement is true (twice), however you're missing the point.
The idea is, that we have the control whether we want too synchronize our collection or not.
Beside this, a Map has various specialized implementations designed for different cases and/or usages (in regards the performance): access, removal, inserting, "ordering", etc..
Hope this helps.
If not, please read the following link:
http://java.sun.com/docs/books/tutorial/collections/index.html
Regards,
Rok
|
SCJP, SCWCD
|
 |
 |
|
|
subject: Collections.synchronizedMap or thread safe classes in collection which one is better?
|
|
|