• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Question synchronized

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello ranchers,

Bettwen Hastable and HashMap.HashMap is synchronize / hashtable. Can anyone tell correct answer.
If HashMap is synchronized , then how can we synchronized it.
Same for Vector, Arraylist and LinkeList, among these which one is synchronized. How can we synchronized them.

Thanks
Dinesh
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think Hashtable is synchronized. And these are standard java API and if one of them is synchronized, that simply means that their implementation present in API provides a synchornized access! But you can apply your own synchronization methods/blocks while using them in your code!
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hashtable is synchronized not Hashtable
Vector is synchronized not ArrayList
you do not need to worry about synchronization while using these collection...synchronized means methods in that classs are synchronized
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

There are two ways to make a hashmap synchronized. One is to call synchronized Map on Collections class and 2nd is to make your own class.
For eg.

Class MyMap extends HashMap {


public synchronized void put(...) {
super.put(...);
}

public synchronized void get(...) {
super.put(...);
}
}

similarly you can synchronized all the methods. So intead of creating an object of HashMap you will be creating an object og MyMap
 
Their achilles heel is the noogie! Give them noogies tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic