The Artima Developer Community
Sponsored Link

Java Buzz Forum
How to Synchronize HashMap in Java with Example

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Javin Paul

Posts: 1090
Nickname: javinpaul
Registered: Jan, 2012

Javin Paul is Java Programmer working on Finance domain.
How to Synchronize HashMap in Java with Example Posted: Feb 7, 2015 9:00 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: How to Synchronize HashMap in Java with Example
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Latest Java Buzz Posts
Latest Java Buzz Posts by Javin Paul
Latest Posts From Java67

Advertisement
HashMap is not synchronized, which means you cannot use it on multi-threaded Java program without external synchronization. In another word, if you share one instance of HashMap between multiple thread, each is either adding, removing or updating entries then it's possible that HashMap loss its structure and not behave as expected. If you have read my earlier article about HashMap, you know that during re-sizing its possible that HashMap exposed to multiple thread, may end up in infinite loop.  In order to avoid this, usually one HashMap instance is used by one thread, sharing of HashMap instance is not allowed, but if you have to share HashMap and there is no option to avoid that, you can always synchronize HashMap in Java. Ofcourse this will affect the performance and probably reduce the speed of HashMap as synchronized method is always slower than non-synchronized one. In this tutorial, we will learn how we can synchornize HashMap in Java.
Read more »

Read: How to Synchronize HashMap in Java with Example

Topic: Java : Collection Framework : TreeMap (SubMap Inclusive) Previous Topic   Next Topic Topic: Java : Collection Framework : TreeMap (SubMap)

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use