troubleshooting Question

synchronization java hashmap

Avatar of Squadless
Squadless asked on
JavaJava EEProgramming
4 Comments2 Solutions646 ViewsLast Modified:
My question is the following,  take a look at the code, one method is synchronized, the other is not.  The hashmap itself is not synchronized.  Is it possible for 2 threads to ever be here: ie: one thread is in the synchronized put block, and another thread is in the getItem method?

Why? Why Not?  Im pretty sure this is impossible for it to happen but i am not 100% sure.

public class Test{
 private HashMap map = new HashMap();

public synchronized void putItem(Object x){
//put code

public Object getItem(Object x){
//get code

Open in new window

Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros