{"comment":{"url":"https://api.github.com/repos/exuugug/SMARTUI/comments/10156438","html_url":"https://github.com/exuugug/SMARTUI/commit/32ebea890349d55452695ee82a391106f2236ff6#commitcomment-10156438","id":10156438,"user":{"login":"exuugug","id":10725451,"avatar_url":"https://avatars.githubusercontent.com/u/10725451?v=3","gravatar_id":"","url":"https://api.github.com/users/exuugug","html_url":"https://github.com/exuugug","followers_url":"https://api.github.com/users/exuugug/followers","following_url":"https://api.github.com/users/exuugug/following{/other_user}","gists_url":"https://api.github.com/users/exuugug/gists{/gist_id}","starred_url":"https://api.github.com/users/exuugug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/exuugug/subscriptions","organizations_url":"https://api.github.com/users/exuugug/orgs","repos_url":"https://api.github.com/users/exuugug/repos","events_url":"https://api.github.com/users/exuugug/events{/privacy}","received_events_url":"https://api.github.com/users/exuugug/received_events","type":"User","site_admin":false},"position":null,"line":null,"path":"","commit_id":"32ebea890349d55452695ee82a391106f2236ff6","created_at":"2015-03-12T02:51:43Z","updated_at":"2015-03-12T02:51:43Z","body":"Forginve my wordy, if we use hashmap, there still will exist thread safety issue.\r\nThe Isemaphore acquire can only make thread safety for two/multiple thread editing same offer/resource.\r\nThere still exists conditions that two request editing two different offer/(other catalog) and trying to do put operations to the same hashmap.\r\nReference:\r\nModifying a HashMap without proper synchronization from two threads may easily lead to a race condition.\r\nWhen a put() leads to a resize of the internal table, this takes some time and the other thread continues to write to the old table.\r\nTwo put() for different keys lead to an update of the same bucket if the keys' hashcodes are equal modulo the table size. (Actually, the relation between hashcode and bucket index is more complicated, but collisions may still occur.)\r\n\r\nI think we should consider using ConcurrentHashMap.\r\n\r\n\r\nFrom: SathyaNarayanan Srinivasan [mailto:notifications@github.com]\r\nSent: Thursday, March 12, 2015 10:10 AM\r\nTo: exuugug/SMARTUI\r\nCc: guang Xu\r\nSubject: Re: [SMARTUI] update ongoingXXXupdates to local hashmap so that no cluster reference (32ebea8)\r\n\r\nStill can’t see the issue…. If Controller is a singleton… then it will have only 1 instance of catalog… which also means only 1 instance of the hash map. Regardless of being stateful or stateless, synchronization and concurency are not related and thus I do not see a connect.\r\n\r\nAnkit, can you please commit these changes to smart-nemesis, for me to review the entire scenario?\r\n\r\nFrom: exuugug <notifications@github.com<mailto:notifications@github.com<mailto:notifications@github.com%3cmailto:notifications@github.com>>>\r\nReply-To: exuugug/SMARTUI <reply@reply.github.com<mailto:reply@reply.github.com<mailto:reply@reply.github.com%3cmailto:reply@reply.github.com>>>\r\nDate: Thursday, March 12, 2015 at 10:05 AM\r\nTo: exuugug/SMARTUI <SMARTUI@noreply.github.com<mailto:SMARTUI@noreply.github.com<mailto:SMARTUI@noreply.github.com%3cmailto:SMARTUI@noreply.github.com>>>\r\nCc: Sathyanarayanan Srinivasan <sathya.narayanan.s@ericsson.com<mailto:sathya.narayanan.s@ericsson.com<mailto:sathya.narayanan.s@ericsson.com%3cmailto:sathya.narayanan.s@ericsson.com>>>\r\nSubject: Re: [SMARTUI] update ongoingXXXupdates to local hashmap so that no cluster reference (32ebea8)\r\n\r\nOk, so now we have one single web applications handling all requests from multiple GUI, and no cluster problem, but still thread safety problem under the single node.\r\nLet’s consider that multiple GUIs send same requests to backend web server, say controller bean OfferCatalogController which is a singleton, then this singleton bean’s method will be call in multiple thread, and when they all want to modify the ConcurrentOfferCatalog which is a property of the bean at the same time, then here comes the thread safety problem, which means that ConcurrentOfferCatalog is making the bean OfferCatalogController stateless, which is a typical spring bean scope caused thread safety problem.\r\n\r\nFrom: SathyaNarayanan Srinivasan [mailto:notifications@github.com]\r\nSent: Thursday, March 12, 2015 9:57 AM\r\nTo: exuugug/SMARTUI\r\nCc: guang Xu\r\nSubject: Re: [SMARTUI] update ongoingXXXupdates to local hashmap so that no cluster reference (32ebea8)\r\n\r\nThe GUI is the only application that will ever need a lock and this webapp is a single function application on tomcat. Hence this comment will not be a valid concern for thread safety under the same node.\r\n\r\nFrom: exuugug <notifications@github.com<mailto:notifications@github.com<mailto:notifications@github.com%3cmailto:notifications@github.com>><mailto:notifications@github.com<mailto:notifications@github.com%3cmailto:notifications@github.com<mailto:notifications@github.com%3cmailto:notifications@github.com%3cmailto:notifications@github.com>>>>\r\nReply-To: exuugug/SMARTUI <reply@reply.github.com<mailto:reply@reply.github.com<mailto:reply@reply.github.com%3cmailto:reply@reply.github.com>><mailto:reply@reply.github.com<mailto:reply@reply.github.com%3cmailto:reply@reply.github.com<mailto:reply@reply.github.com%3cmailto:reply@reply.github.com%3cmailto:reply@reply.github.com>>>>\r\nDate: Thursday, March 12, 2015 at 9:54 AM\r\nTo: exuugug/SMARTUI <SMARTUI@noreply.github.com<mailto:SMARTUI@noreply.github.com<mailto:SMARTUI@noreply.github.com%3cmailto:SMARTUI@noreply.github.com>><mailto:SMARTUI@noreply.github.com<mailto:SMARTUI@noreply.github.com%3cmailto:SMARTUI@noreply.github.com<mailto:SMARTUI@noreply.github.com%3cmailto:SMARTUI@noreply.github.com%3cmailto:SMARTUI@noreply.github.com>>>>\r\nCc: Sathyanarayanan Srinivasan <sathya.narayanan.s@ericsson.com<mailto:sathya.narayanan.s@ericsson.com<mailto:sathya.narayanan.s@ericsson.com%3cmailto:sathya.narayanan.s@ericsson.com>><mailto:sathya.narayanan.s@ericsson.com<mailto:sathya.narayanan.s@ericsson.com%3cmailto:sathya.narayanan.s@ericsson.com<mailto:sathya.narayanan.s@ericsson.com%3cmailto:sathya.narayanan.s@ericsson.com%3cmailto:sathya.narayanan.s@ericsson.com>>>>\r\nSubject: Re: [SMARTUI] update ongoingXXXupdates to local hashmap so that no cluster reference (32ebea8)\r\n\r\n\r\nSorry, even only one spring web server, there are still thread safety issue operating the hashmap, because the OfferCatalogController is not stateless, might need to add synchronization/lock when acquire/release the lock on the hashmap operation part , if multiple web server, then need cluster wide synchronization.\r\n\r\n—\r\nReply to this email directly or view it on GitHub<https://github.com/exuugug/SMARTUI/commit/32ebea890349d55452695ee82a391106f2236ff6#commitcomment-10156020>.\r\n\r\n\r\n—\r\nReply to this email directly or view it on GitHub<https://github.com/exuugug/SMARTUI/commit/32ebea890349d55452695ee82a391106f2236ff6#commitcomment-10156042>.\r\n\r\n—\r\nReply to this email directly or view it on GitHub<https://github.com/exuugug/SMARTUI/commit/32ebea890349d55452695ee82a391106f2236ff6#commitcomment-10156092>.\r\n\r\n\r\n—\r\nReply to this email directly or view it on GitHub<https://github.com/exuugug/SMARTUI/commit/32ebea890349d55452695ee82a391106f2236ff6#commitcomment-10156117>.\r\n"}}