You are on page 1of 3

7/14/13

Question synchronized (SCJP forum at JavaRanch)

File APIs for Java Developers Manipulate DOC, XLS, PPT, PDF and many others from your application. http://aspose.com/file-tools

A friendly place for programming greenhorns!

Big Moose Saloon


Search

Java FAQ

Recent Topics

Register / Login

JavaRanch Java Forums Certification Programmer Certification (SCJP/OCPJP)

Author
Dinesh Tahiliani Ranch Hand Joined: Aug 06, 2007 Posts: 486

Question synchronized
posted 2/21/2008 10:41 AM

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

Thanks<br />Dinesh

Nadeem Khan Ranch Hand Joined: Nov 27, 2007

posted 2/21/2008 11:35 AM

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
1/3

https://www.coderanch.com/t/267634/java-programmer-SCJP/certification/synchronized

7/14/13

Question synchronized (SCJP forum at JavaRanch)

Posts: 108

API provides a synchornized access! But you can apply your own synchronization methods/blocks while using them in your code!

<i>If there were no Exceptions (not Errors!), Life would have kinda sucked!!</i>

Sunny Malik Ranch Hand Joined: Dec 30, 2007 Posts: 86

posted 2/22/2008 5:05 AM

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

Research is what I'm doing when I dont know what I'm doing

Rah Gupta Greenhorn Joined: Nov 20, 2007 Posts: 3

posted 2/22/2008 2:04 PM

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

Granny's Programming Pearls "inside of every large program is a small program struggling to get out" JavaRanch.com/granny.jsp

https://www.coderanch.com/t/267634/java-programmer-SCJP/certification/synchronized

2/3

7/14/13

Question synchronized (SCJP forum at JavaRanch)

subject: Question synchronized

Similar Threads synchronized class Could Class be synchronized ? Making a class synchronized synchronized keyword use ArrayList & Vector
All times above are in your local time zone & format.T he current ranch time (not your local time) is Jul 14, 2013 09:01:24 .

Contact Us | Powered by JForum |

C opyright 1998-2013 Paul W he aton

https://www.coderanch.com/t/267634/java-programmer-SCJP/certification/synchronized

3/3

You might also like