dcsimg
Is synchronization required to add and get objects from Vector and hashtable
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Naila_Joseph
Posted On:   Wednesday, February 13, 2002 06:31 AM

In my application more then one threads are accessing a Vector and hashtable. Do I need to synchronize methods which add or gets objects from these two type of collections.?

Re: Is synchronization required to add and get objects from Vector and hashtable

Posted By:   Chinmay_Bajikar  
Posted On:   Wednesday, February 13, 2002 08:10 PM

Naila,

If ur method does two operations ex PUT & GET from

the Collection then, even though the two methods PUT & GET

are synchronized, but ur actual method is not.


So it is possible that 2 threads are in ur method at a time


One trying to PUT and another trying to GET.



So even though Vector and HashTable are synchronized

they do not help in the situation described above .

Coz the synchronization is on methods,i.e the thread is restricted

for that block of code only.




See if ur method(or the object) needs to be synchronized after reading this.

And let me know if my answer helped.

Thanks

Re: Is synchronization required to add and get objects from Vector and hashtable

Posted By:   Stefan_Mensink  
Posted On:   Wednesday, February 13, 2002 07:23 AM

No, these two classes are synchronized. The not-synchronized version for a Hashtable is for instance a Hashmap.
About | Sitemap | Contact