Alternative to DCL with Maps

Hi,
"Double-Check Locking" with HashMap is broken, but it has (not working) features we may need to reproduce:
1. Efficient get if a value is already present in the map.
2. Single value creation (if value is absent).
The public V putIfAbsent(K key, V value) method in ConcurrentHashMap seems strange at first since it requires an instance of the value you want to retreive (and this value creation may be costly).
So, how to implement an efficient alternative to DCL ?
First, I could think about a simple synchronized method:
private final Map<K, V> cache = new HashMap<K, V>();
public synchronized V get(K key) {
    V value = cache.get(key);
    if (value == null) {
        value = new ...; // create fully initialized value
        cache.put(key, value);
    return value;
}Actually, DCL what created to avoid exactly this kind of code, but modern JVMs (5 and even more 6) seem to implement synchronized methods efficiently.
Second, I could use ConcurrentHashMap this way:
private final ConcurrentHashMap<K, V> cache = new ConcurrentHashMap<K, V>();
public V get(K key) {
    V value = cache.get(key);
    if (value == null) {
        value = new ...; // create fully initialized value
        value = cache.putIfAbsent(key, value);
    return value;
}This code does not prevent multiple value creations but it ensures that only one instance is put in the map and returned to all calling threads.
Third, I could extend ConcurrentHashMap with a kind of "if-absent" value creator:
public interface ValueCreator<V> {
    public V create();
public class Cache<K, V> extends ConcurrentHashMap<K, V> {
    public V putIfAbsent(K key, ValueCreator<V> creator) {
        // complicated code since we have to re-implement Segment.put(...)
}This last code is not only complicated but potentially dangerous since we don't know what is done in ValueCreator.create (what happens if the create method tries indirectly to access the cache itself?)
I would really appreciate if some concurrency guru could give me good hints about those recurrent questions:
1. What about synchronized performances in Java 5/6 ?
2. Are there better solutions for DCL alternatives ?
Regards,
Franck.
.

Read 13.2 and 16.2.4 of Java Concurrency in Practice(Goetz et al, Addison-Wesley).

Similar Messages

  • Problem with maps on e72

    Hi everyone
    I've got a problem with maps on my E72.
    I've seen advert that Nokia is going to let everyone use maps for free on selected models.
    I was going to buy Sat Nav for whole Europe as I travel a lot and I was going to change my old N95. I thought I could do both in one new phone. Checked all the available models and chose E72. It said it;s got GPS and you don't need to use your network and spend fortune on internet connection. Got it from eBay for £270.
    I installed Ovi Maps from internet and the first thing that surprised me was it had 'only' 7-8MB.
    I thought that something was wrong, maps for 72 countries couldn't be 8MB big.
    After some time I managed to set my e72 up. Put my Maps on and...
    It takes loads of time to find GPS connection, but the worst thing is if I type lets say Paris it doesn't find anything. Map has wholes, like suddenly the roads end and there's nothing there.
    My question is what am I doing wrong? Do I need to download something more? I didn't have any maps on my phone when I bought it. Where can I find them?
    If someone could help I'd appreciate it.
    Thanks a lot.

    I forgot to mention that when I choose a destination it keeps saying Calculating route all the time. I waited about 15 minutesand it didn't calculate anything.

  • Problem with maps in Mavericks on iMac

    I have a problem with my Maps on Mavericks.
    I can open it just fine, no crash or whatever but the map itself just won't load, whatever mode it is on. Here is the screenshot of my Maps:
    As you can see, it just stays blank all the time.
    I'm  also running Parallels 9 and don't know if that has something to do with problem.

    Spent days trying various fixes, but this is the one that did it for me. Thanks!
    livetowin
    Re: Problem with maps in Mavericks on iMac 
    Dec 8, 2013 7:14 PM (in response to robin1943)
    Try this
    Since my date and time were incorrect and imessage was not working as well, I tried this
    1. Go to system preferences and click date and time
    2. Select date and time tab
    3. Uncheck "set date and time automatically" and manually enter the correct time
    4. Go to time zone tab and uncheck the box there too
    5. Go back to date and time tab and now check the box "set date and time automatically"
    6. Then check the box in time zone as well
    Now open maps and see if it works!

  • Problems with mapping after bundling messages into one XML-file

    Hi all,
    Case 1: one DebMas IDoc ==> XI ==> one XML-file : no problems with mapping.
    Case 2: several DebMas IDoc's ==> XI ==> one XML-file : problems with mapping.
    Explanation:
    Incoming DebMas IDoc's:
    Businesspartner 1 : no Customer Master Partner Functions (E1KNVPM).
    Businesspartner 2 : Customer Master Partner Functions (E1KNVPM).
    Businesspartner 3 : Customer Master Partner Functions (E1KNVPM).
    Businesspartner 4 : Customer Master Partner Functions (E1KNVPM).
    After bundling into one XML-file:
    Businesspartner 1 : no Customer Master Partner Functions (E1KNVPM).
    Businesspartner 2 : no Customer Master Partner Functions (E1KNVPM) !!!!
    Businesspartner 3 : Customer Master Partner Functions of Bp 2 (E1KNVPM) !!!!.
    Businesspartner 4 : Customer Master Partner Functions of Bp 3 (E1KNVPM) !!!!.
    All the payloads of the IDoc's are correct.
    In the message mapping we use a Container for the Partner Functions (shown as below)
    Is this a serious bug in the mapping of SAP XI ?
    Does anyone knows how to solve this serious problem.
    E1KNVVM -
    > Partner_Container
    E1KNVPM -
    > Partner
       PARVW -
    > ParnerRole
       KUNN2   -
    > PartnerNumber
    Regards,
    Theo Pijlman

    Hi,
    Example:
    Input idoc has field F1 with occurence 0..unbnd
    My input values for field F1 is
    1
    none
    2
    3
    Say, I have a mapping, F1---->TargetF1
    In the target only 3 TargetF1s will be created for the values 1,2,3 and nothing will be created for the field F1 with no value.
    To overcome this, use collapse contexts.
    F1->collapsecontexts>TargetF1
    This way, the TargetF1 fields created will have the following values:
    1
    blank
    2
    3
    Collapse contexts makes sure that a target is created, even if there is a context change specified at the source.
    Hope this is clear.
    Regards,
    Smitha.

  • E71 with Maps 2... should I stay or should I go......

    Currently in China... fantastic country...amazing cold spell... snow 3m thick in places... Europe appears the same... still a working off line version of maps would be very useful...
    I have an E71 phone with maps 2 and the chat seems to be I'm better of staying with this version than Ovi3... Are the issues with Maps 3 fixed? and could someone point this poor ludite to the link to the upgrade?
    Xiexie

    No cell company due to a correct bill go and forgive that $60.
    Let's say one million customers all called and because they also did not back date the plan now all owe $60 or more and call in and ask for an accommodation just look at how much money Verizon would lose.
    No carrier will do what you ask.
    So my advice is to go and see if another carrier will do what you wish.
    But remember, there are activation fees and plan fees and you have to spend more money on new devices. Makes sense spend $800+ to save $60.
    Good Luck

  • Error 2001 with Maps applicaion

    Hi,
    I have a problem with maps on my BB Q10. I currently live in the Czech Republic and whenever I search for an existing location like "Brno, Opletalova" it's found and offered in the list. After I select it to be shown I get this error:
    "There is a problem communicating with the server. Try again later (2001)"
    Though searching for simple location like cities works normally. This problem happens only when I search for streets and similar.
    I would appriciate any help with this.
    Thanks,
    Peter

    There was someone from Hungary the other day with same issue. From some of the responses I gather there are or were issues in Hungary.
    I did a search and found others in Czech Republic reporting the issue, but I didn't pay close attention to the dates of the threads.
    That is why I suggested it might be a problem that is location wide.
    At any rate I don't believe (and I guess you don't either) that it is a matter within your control.
    - Ira

  • Help with mapping the mod_plsql path with Apache

    Hi,
    I need help with mapping my pl/SQL Handler path.
    Currently i have an URL like this :
    http://myhost.com/pls/DADUSER/PLSQLPROC?param1=123
    But I need something like :
    http://myhost.com/d/PLSQLPROC?param1=123
    I tried to rename the "Location Handler" from "pls" to "d", works great, but it always appends my Default DAD User to the URL.
    And I tried to map my PL/SQL Handler to "/" and create a DAD User called "d" and set it to default. Didn't worked...
    Any help is appreciated....
    Bye,
    Oliver
    null

    Oliver,
    try to use the rewrite directive or the
    rewrite engine (mod_rewrite).
    Please see the Online documentation for how
    to do this:
    http://technet.oracle.com/docs/products/ias/doc_library/1021doc_otn/comm.102/a87562/apptroub.htm
    Hope it helps
    -Stefan

  • Problem with mapping the Entity beans onto database tables

    Hi,
    I got a problem with mapping the Entity beans onto database tables. Here are what I did:
    First Step:
    asant capture-schema
    Second Step:
    capture-schema -driver com.pointbase.jdbc.jdbcUniversalDriver -dburl jdbc:pointbase:server://localhost/sun-appserv-samples -username pbPublic -password pbpublic -table APPLICANT -table APPLICANTSKILL -table CUSTOMER -table LOCATION -table job -table JOBSKILL -table SKILL -out build/agency.dbschema
    The first step was fine. But, in the second step, I got the error message as follow:
    using dburl:jdbc:pointbase:server://localhost/sun-appserv-samples
    using username:pbPublic
    using password:pbpublic
    using driver:com.pointbase.jdbc.jdbcUniversalDriver
    using schemaname:null
    using output file:build/agency.dbschema
    JDO71100: Failed to find a class. Verify that the class is available on your CLASSPATH
    java.lang.ClassNotFoundException: com.pointbase.jdbc.jdbcUniversalDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:141)
    at com.sun.forte4j.modules.dbmodel.jdbcimpl.ConnectionProvider.<init>(Co
    nnectionProvider.java:38)
    at com.sun.jdo.api.persistence.mapping.ejb.CaptureSchema.main(CaptureSch
    ema.java:130)
    at com.sun.jdo.spi.persistence.support.ejb.util.CaptureSchemaWrapper.mai
    n(CaptureSchemaWrapper.java:29)
    Thanks for your help!

    You need to add the pbclient.jar or some similar name like that, in the CalssPath.

  • Routing with Maps and Contacts

    Before 1.1.3 update, I was able to select an address from a contact and use it as source or destination. After installing the 1.1.3 update, nothing gets selected from the contacts while routing with maps.

    Yep...its a glitch of some sort. Go into your contacts and edit the address. Then, select the country from the scroll menu. That should fix it up. Major pain though to do that with every contact for which you have an address.

  • Send With Map of Attachments & Map Variable

    I'm trying to send multiple attachments using "Send With Map of Attachments" Service.  I've setup a map variable (attachments_map) of sub-type string to hold the path and file name for each file (represented as <full_path>/<file_name>.pdf).<br /><br />What I'm confused about is that I don't understand the keys of the map given the following statement in the help file about this specific Email service: "The keys for the map are the attachment file names. The file names should include the file name extension if the email receiver needs to associate the file with software to open it."<br /><br />I have two questions:<br /><br />1)  What are the keys for the map needed for the "Send With Map of Attachments" service for Attachments and what is the XPath representation to send this data to the service (e.g., /process_data/attachment_map/@file[0] or /process_data/attachment_map/@file[<file_name>] or what) ?  I don't know what the required XML structure looks like.  As you can tell, I've not used a map variable before either!  :)<br /><br />2)  As in the "Send With Document" service, is there a way to define the file name saved in the e-mail that the receiver sees?<br /><br />Example:<br />Receiver sees this in e-mail:  "File.pdf"<br />But the path and file are actually this:  T:/Files/XXXX_File.pdf<br /><br />Thanks for your help in advance!

    FINALLY figured this out! I configured a map variable of sub-type document called "attachment_map". I have the files that are to be attached stored in a database, and I used the component Query for Multiple Rows to get the attachment data into an XML document. I then built an iterative process loop to parse the XML (using the NodeSet functions count() and position() to control this) loading the file name for each file (the map key) into the process variable "attachment_file_name" and the full file path and name into another variable "attachment_file_full_path". The process loads the documents (one at a time) into the map variable using the Foundation file utility Read Document - the input variable is /process_data/@attachment_file_full_path and the output variable is /process_data/attachment_map/[@id=/process_data/@attachment_file_name]. After the map is loaded with all the attachments I wanted, I used the Send With Map of Attachments component with /process_data/attachment_map/ as my Attachments variable. As long as the file names are unique, they all came through.

  • 3 issues with mapped-superclass

    I created a superclass for my entities which is a simple pojo with 4 properties. I mapped it in JPA with mapped-superclass.
    I want the 'ownerId' and 'created' fields to be read-only on the API, in other words, the pojo shouldn't have setters for those 2 fields.
    TLE objects violently to the absence of those setters. I throws a NPE (see below).
    Secondly, I decided I could live without the read-only requirement, so I put the setters on the pojo, set the mapping's access= to access="FIELD" so that the setters are not called. Out of curiosity, I threw exceptions in the setters just to make sure.
    TLE insists on calling the setters, regardless of the 'access' mode I choose. It's always PROPERTY access which is used. FIELD is ignored.
    So I can live with that too. However once I managed to deploy the whole JPA and started testing it, I realised the prePersist event listener isn't called as it is should be according to the mapping I defined. The prePersist callback is in the mapped-superclass entity mapping and calls a method on the superclass. However it isn't called.
    Does anybody here use mapped-superclass without trouble, or is there an example app out on the net demonstrating its use without issues?
    This is TLE build 58g-fcs, btw.
    Regards
    Adam
    java.lang.NullPointerException
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.objects.MetadataMethod.getSetMethodName(MetadataMethod.java:69)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.MetadataAccessor.getSetMethodName(MetadataAccessor.java:330)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.MetadataAccessor.setAccessorMethods(MetadataAccessor.java:575)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.BasicAccessor.processDirectToFieldMapping(BasicAccessor.java:182)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.BasicAccessor.process(BasicAccessor.java:160)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.ClassAccessor.processAccessor(ClassAccessor.java:528)
         at oracle.toplink.essentials.internal.ejb.cmp3.xml.accessors.XMLClassAccessor.processAccessors(XMLClassAccessor.java:371)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.ClassAccessor.processMappedSuperclass(ClassAccessor.java:1128)
         at oracle.toplink.essentials.internal.ejb.cmp3.xml.accessors.XMLMappedSuperclassAccessor.process(XMLMappedSuperclassAccessor.java:67)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.ClassAccessor.processMappedSuperclasses(ClassAccessor.java:1138)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.ClassAccessor.process(ClassAccessor.java:495)
         at oracle.toplink.essentials.internal.ejb.cmp3.xml.accessors.XMLClassAccessor.process(XMLClassAccessor.java:322)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProcessor.processMappingFile(MetadataProcessor.java:568)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProcessor.processMappingFiles(MetadataProcessor.java:533)
         at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:368)
         at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:607)
         at oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer.callPredeploy(JavaSECMPInitializer.java:171)
         at oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer.initPersistenceUnits(JavaSECMPInitializer.java:239)
         at oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer.initialize(JavaSECMPInitializer.java:255)
         at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createEntityManagerFactory(EntityManagerFactoryProvider.java:155)
         at javax.persistence.Persistence.createFactory(Persistence.java:172)

    https://glassfish.dev.java.net/issues/show_bug.cgi?id=4414

  • Performance considerations with mapping outside the BPE

    Hello together,
    we have an Integration Process with 2 more or less complex transformations steps (i.e. Message Merging).
    Since the overall performance is rather poor, we consider to let the mapping take place outside the IP. This
    means we would have no more transformation step within our IP. Instead we use Interface-Mappings between
    the abstract an the Inbound-Interfaces.
    Does anybody know  whether this approach leads to any significant performance advantages or not?
    Regards Gunnar

    The design with mapping outside BPM is always better in terms of performance.
    Regards,
    Prateek

  • Paltry Results with Maps

    I live in Guangzhou (Canton to some), China and I started Maps using that location. When I checked out Kyushu, Japan (where my daughter lives now) there was hardly anything there. The Fukuoka Airport is in Simplified Chinese, sub-headed with Japanese, and there is no English anywhere. A few major attractions show up, but nothing else- only a bunch of lonely highways with no names. There is no hybrid, sattelite, or close up view; just a blackout grid with question marks.
    I'm not jumping to conclusions and saying this is censorship on China's part (or Japan's), and I am on a VPN. So what's up? Where are the unagi eels and picturesque canals of Yanagawa for starters??
    Of course I know that I can just go to Google Maps (I did) and get all the info I need, and then some. I did that too. I guess what I'm trying to get to is this: what is Apple trying to acheive with Maps? It's prominently displayed, sitting in the Dock (er, was), and it seems like Apple really wants you to use it and go head to head with Google. And yet, look at the experience I had. Not something Apple intended I'm sure. The only big difference I can think of is that Maps asks if you want to you use your current location, while Google just throws North America in my face. So whatever sensitivity or intuitiveness Apple might be aiming for, it doesn't seem to be working over here in this neck of the globe.

    This can be done by using a PL/SQL substring function to trim the results. For this alias, since you know the length of this alias. You could write the query as follows:
    SELECT substr(m, 31)
    FROM TABLE(SDO_RDF_MATCH(
    '(?m rdf:type :Male)',
    SDO_RDF_Models('family'),
    SDO_RDF_RuleBases('RDFS'),
    SDO_RDF_Aliases(SDO_RDF_Alias('','http://www.example.org/family/')),
    null));

  • What to do NOT ask Google maps permit every open a page with maps functionality, phonegap app? If from my App go to clik a you tube link or google maps link there is no way return back – I know – but when click home after click app  opens you tube, what t

    In iOS6 emulator i plan to migrate soon to iOS7
    What to do NOT ask Google maps permit every open a page with maps functionality(custom maps), in phonegap app?
    If from my App go to click a you tube link or google maps link there is no way return back – I know – but when click home after click app opens you tube, what to do to return in the actual app from where clicked the you tube link?
    I tried but no way see shot attached xcode errors…

    It would make more sense to ask for help with PhoneGap on their support site.

  • Trying to download update to CoPilot Live and CoPilot GPS with maps.  files sizes are large and taking hours to download on wireless connection.  How can I download App updates and new maps while connected to PC and Itunes through hard wire internet link?

    Trying to download update to CoPilot Live and CoPilot GPS with maps.  Files sizes are large and taking hours to download on wireless connection.  How can I download updates and new maps while connected to PC and Itunes through hard wire internet link?

    I'm on my iPad, so I don't know if this is the page with an actual download. I don't see a button, but assume that is because I  am on an iPad. It is in the DL section of Apple downloads.
    http://support.apple.com/kb/DL1708

Maybe you are looking for

  • Can't scan to mac

    I have tried all the tips in the messages but I cannot scan to my Mac.  I tried also using the HP utility and it says it scans an overview, but I cannot find the files on the computer.  Here is the message I am getting.  The printer function works fi

  • AuC to Fixed Asset Settlement... (through Investment Management)

    Hi, Is there any way wherein I can settle the AuC to Fixed Asset without clearing down payments related to that AuC? Kindly assist....

  • Soundbooth -- Use with Premiere Elements 4?

    I tried Premiere CS3, but decided on Elements 4 for ease of use and price. So far it seems to be a fine product but the limited audio editing capabilities led me, on advice from my son, to try Soundbooth. So far, Soundbooth has done an excellent job

  • Connect button in excel does not respond with server connection dialog box

    Hi all, I have installed Essbase 11.1.1 spreadsheet client and when I try to connect to the server from the excel add in using Essbase->Connect option, the "Essbase System Login" dialog box does not pop up. Also no error messages are displayed. OS is

  • Error converting image     get error msg when trying to display thumbnail

    Hi there Me again I am having some problems displaying thumbnails I keep getting the error Error converting image (create thumbnail). The "...........public_html/productimages/thumbnails/" folder has no write permissions. So I go to my host and chang