{"id":1544,"date":"2017-08-25T21:15:30","date_gmt":"2017-08-26T01:15:30","guid":{"rendered":"http:\/\/shirishranjit.com\/blog1\/?page_id=1544"},"modified":"2017-08-25T21:37:04","modified_gmt":"2017-08-26T01:37:04","slug":"can-a-hashmap-degeneration-how-can-it-happen","status":"publish","type":"page","link":"https:\/\/shirishranjit.com\/blog1\/java-stuff\/can-a-hashmap-degeneration-how-can-it-happen","title":{"rendered":"HashMap &#8211; Unintended consequence in Multi-threaded environment &#8211; HashMap Degeneration &#8211; How can it happen?"},"content":{"rendered":"<p>A HashMap is designed to build for only one purpose &#8211; hold key-value for a single threaded events. A map is very efficient for this purpose. However, you diverse from the fundamentals of why a HashMap exist, then you are charting into an extremely dangerous section of programming world &#8211; race condition, infinite loops that is basically Degeneration. <\/p>\n<p>Thus, a simple hashmay in multi-threaded environment will cause one time to spin out of control. To avoid such pain in production, use synchronized HashMap in all your applications.<\/p>\n<p>Refer to the blog post for the detail explanation on how a race condition in Hashmap can cause this issue of going into infinite loop.<\/p>\n<h2>Reference<\/h2>\n<ol>\n<li><a href=\"http:\/\/mailinator.blogspot.hu\/2009\/06\/beautiful-race-condition.html?m=1\">a good point on Race condication in Hashmap implimentation<\/a><\/li>\n<li><a href=\"https:\/\/bugs.openjdk.java.net\/browse\/JDK-6484560\">Hashmap degeneration is not a bug<\/a><\/li>\n<\/ol>\n<div class=\"twttr_buttons\"><div class=\"twttr_twitter\">\n\t\t\t\t\t<a href=\"http:\/\/twitter.com\/share?text=HashMap+-+Unintended+consequence+in+Multi-threaded+environment+-+HashMap+Degeneration+-+How+can+it+happen%3F\" class=\"twitter-share-button\" data-via=\"\" data-hashtags=\"\"  data-size=\"default\" data-url=\"https:\/\/shirishranjit.com\/blog1\/java-stuff\/can-a-hashmap-degeneration-how-can-it-happen\"  data-related=\"\" target=\"_blank\">Tweet<\/a>\n\t\t\t\t<\/div><div class=\"twttr_followme\">\n\t\t\t\t\t\t<a href=\"https:\/\/twitter.com\/shiranjit\" class=\"twitter-follow-button\" data-size=\"default\"  data-show-screen-name=\"false\"  target=\"_blank\">Follow me<\/a>\n\t\t\t\t\t<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>A HashMap is designed to build for only one purpose &#8211; hold key-value for a single threaded events. A map is very efficient for this purpose. However, you diverse from the fundamentals of why a HashMap exist, then you are &hellip; <a href=\"https:\/\/shirishranjit.com\/blog1\/java-stuff\/can-a-hashmap-degeneration-how-can-it-happen\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"parent":524,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1544","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/1544"}],"collection":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/comments?post=1544"}],"version-history":[{"count":7,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/1544\/revisions"}],"predecessor-version":[{"id":1551,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/1544\/revisions\/1551"}],"up":[{"embeddable":true,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/524"}],"wp:attachment":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/media?parent=1544"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}