logo
down
shadow

ConcurrentHashMap of Future and double-check locking


ConcurrentHashMap of Future and double-check locking

By : Kobayakawa Ammad
Date : November 22 2020, 11:12 AM
I think the issue was by ths following ,
Do I need to perform double-check locking control in my getTask method?
code :


Share : facebook icon twitter icon
Should I double check before and after locking a list?

Should I double check before and after locking a list?


By : Charles Scott
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Theory:
Once a thread acquires the _SyncLockObject lock all other threads reentering that method will have to wait for the lock to be released.
With double-checked locking, does a put to a volatile ConcurrentHashMap have happens-before guarantee?

With double-checked locking, does a put to a volatile ConcurrentHashMap have happens-before guarantee?


By : Phil305
Date : March 29 2020, 07:55 AM
hope this fix your issue Yes, it is correct. volatile protects only that object reference, but nothing else.
No, putting an element to a volatile HashMap will not create a happens-before relationship, not even with a ConcurrentHashMap.
code :
public class ObjectContainer {
    volatile boolean isSetupDone = false;
    Object o;
}

static ConcurrentHashMap<String, ObjectContainer> containers = 
    new ConcurrentHashMap<String, ObjectContainer>();

public Object getInstance(String groupId) {
  ObjectContainer oc = containers.get(groupId);
  if (oc == null) {
    // it's enough to sync on the map, don't need the whole class
    synchronized(containers) {
      // double-check not to overwrite the created object
      if (!containers.containsKey(groupId))
        oc = new ObjectContainer();
        containers.put(groupId, oc);
      } else {
        // if another thread already created, then use that
        oc = containers.get(groupId);
      }
    } // leave the class-level sync block
  }

  // here we have a valid ObjectContainer, but may not have been initialized

  // same doublechecking for object initialization
  if(!oc.isSetupDone) {
    // now syncing on the ObjectContainer only
    synchronized(oc) {
      if(!oc.isSetupDone) {
        oc.o = new String("typically a more complicated operation"));
        oc.isSetupDone = true;
      }        
    }
  }
  return oc.o;
}
Map synchronization with double check locking

Map synchronization with double check locking


By : user2124045
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , It's safe, but it doesn't have any advantages in this case.
Double-checked locking is used to avoid costly synchronization on the most frequent code path, but in your case get() is synchronized as well, therefore you actually have two synchronized blocks instead of one.
Double-check locking issues, c++

Double-check locking issues, c++


By : Bhazo
Date : March 29 2020, 07:55 AM
around this issue The problem you describe can only occur if for reasons I cannot imagine the conceptors of the singleton uses an explicit (and broken) 2 steps construction:
code :
     ...
     Guard myGuard(lock_); 
     if (!pInstance_) 
     {
        auto alloc = std::allocator<Singleton>();
        pInstance_ = alloc.allocate(); // SHAME here: race condition
        // eventually other stuff
        alloc.construct(_pInstance);   // anything could have happened since allocation
     }
     ....
        auto alloc = std::allocator<Singleton>();
        Singleton *tmp = alloc.allocate(); // no problem here
        // eventually other stuff
        alloc.construct(tmp);              // nor here
        _pInstance = tmp;                  // a fully constructed instance
Why does ConcurrentHashMap work in Double Checked Locking

Why does ConcurrentHashMap work in Double Checked Locking


By : Mayur Vachchewar
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Happens before actually is the key here. There's a happens before edge extending from map.put(key, object) to a subsequent map.get(key), therefore the object you retrieve is at least as up to date as it was at the time it was stored in the map.
Related Posts Related Posts :
  • Support multi-language
  • Why does Hibernate @OneToOne execute multiple select queries instead of one?
  • How to modify the height and width of a LinearLayout programmatically for a customAlertDialog?
  • Java getting every second element from array list and using it as value for hash map
  • Jmap error "More than one non-option argument"
  • Thread.uncaughtExceptionHandler does not catch DataFormatException, FileAlreadyExistsException and NoSuchFileException
  • After navigating to each link in the webpage,how to get list of all forms with method =post using selenium java
  • Launch a specific Spring Boot service from a codebase containing several
  • How do I cast a Java Object into a List of integers?
  • The method andProperty(String) from the type QueryBuilder is deprecated - Javers
  • I don't understand the difference in output between System.out.println((char)b) and System.out.write((char)b)
  • How to support multiple source level targets in an annotation processor
  • Is there a way to save the obtained output from a a process object's getOutPutStream() method into a file
  • How to use item touch helper with heterogeneous view types?
  • Tap button again to confirm action
  • Getting wrong characters from Clob field in Oracle using java jdbc
  • Run multiple call in parallel go generate object using Futures
  • Unparseable date Exception java date pattern
  • Stored procedures call (namedparameterjdbctemplate)
  • com.google.firebase.database.DatabaseException: Failed to convert a value of type java.lang.String to long
  • Java - Scanner .next() doesn't read string that contains a space
  • Set a timer for the visibility of a button
  • Unirest gives NoSuchMethodError when using asString method
  • Abstract Controller in Spring
  • Map an instance containing a list to a flatMap (using stream)
  • JPanel is added onto other Jpanel on togglebutton Click
  • Mysterious " The color components or name must be specified " error in JavaFX ListView
  • How to set up blocking asynchronous request/response in project reactor?
  • How can i achieve the same functionality with Java 8 using streams
  • How to verify a password without sending it unencrypted to a server
  • While fetching all links,Ignore logout link from the loop and continue navigation in selenium java
  • Issues using spring boot with MySQL database
  • Method unmodifiablelist() cannot be applied to given type
  • Does using the fragments lower down the load on main activity
  • Cannot read resource as stream when running jar
  • JPA criteria produce a query with just a one question point
  • Upload data to the Azure ADLS Gen2 from on-premise using Python or Java
  • Netty server send a byte[] encoded by Protobuf, but C# client Socket.Receive keeps being 0
  • How to add string at the bottom of a ScrollView
  • Using the instantiated collection type for Jackson deserialization instead of initializing a new one?
  • Firebase Realtime Database Update Data - Android Java
  • Move to main thread after another thread go to sleep
  • use of lambda and streams on nested object
  • OneDrive authentication using ADAL4J
  • How to get lines starting with some word from file and if no match get lines starting with another word
  • Is there alternative for Java's ' byte[] decodeFile = Base64.getMimeDecoder().decode(fileBase64); ' in Python?
  • filter minimum value from custom java array list
  • PowerMock static method mocking isn't taken into account for each @InjectMocks invocation
  • Spring Boot LazyInitializationException inside Transaction
  • Getting field name as string for already defined class. Is that possible?
  • List the largest possible cuboids inside a 16x16x16 matrix
  • Reading Int value of bytes from inputStream
  • How to fix text change listener error when I implement it?
  • How to send XML file to ActiveMQ?
  • @PropertyId annotation "is disallowed for this location"
  • Single Ignite node does not stop TCP discovery
  • While loop stop condition missing
  • How to register a listener on a OID / Managed Object using SNMP4J to act on set or get requests the agent receives?
  • maven issue with profiles
  • How to properly implement a sensor with SensorManager in a thread?
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org