I'm looking for explanations about the synchronized blocks. Consider this category -
Public category A {map map; Public getValue (string key) {back to map.get (key); } Remove public (string key) {synchronize (map) {map.remove (key); }}} A Singleton is GetValue is heavily accessed by heavy threads in the app by app. I'm adding a new method, removing which one from the map Removes the key. If deletion is applied as above,
- When a thread is in the synchronized block of the extracted method, I think it will get a lock on the map object. Does this mean that other threads trying to access the map via getValue method will be blocked? (I would love them.)
- When a thread is not in the synchronized block of extract, the thread should normally reach the getValue method function. Does not block each other? (I like that one too).
I should get the block to getValue thread only if there are no extracting threads to execute.
itemprop = "text">
One of the synchronized rules is that only one thread is synchronized (foo) at a time. may be in the block foo. This is the synchronize of the only rule. OK, there are some complex things of memory constraints and likes, and single threads have multiple nested codes for the same foo at the same time > Synchronize (foo) can be in block: null object () {synchronize (af) {stuff;); // It works fine! }} Zero stuff () {synchronize (foo) {doMoreStuff (); }} ... but the above rule is basically the key to understanding synchronize .
Comments
Post a Comment