Best practice for ConcurrentHashMap use?

Hi All, would the following be considered "best practice", or is there a better way of doing the same thing? The requirement is to have a single unique "Handler" object for each Key:
public class HandlerManager {
    private Object lock = new Object();
    private Map<Key,Handler> map = new ConcurrentHashMap<Key,Handler>();
    public Handler getHandler(Key key) {
        Handler handler = map.get(key);
        if (handler == null) {
            synchronized(lock) {
                handler = map.get(key);
                if (handler == null) {
                    handler = new Handler();
                    map.put(key, handler);
        return handler;
}Clearly this is the old "double-checked-locking" pattern which didn't work until 1.5 and now only works with volatiles. I believe I will get away with it because I'm using a ConcurrentHashMap.
Any opinions? is there a better pattern?
Thanks,
Huw

My personal choice would be to use the reliable "single-checked-locking" pattern:
    public Handler getHandler(Key key) {
        synchronized(lock) {
            Handler handler = map.get(key);
            if (handler == null) {
                handler = new Handler();
                map.put(key, handler);
            return handler;
    }But I'm afraid the Politically Correct way of doing it nowadays looks as ugly as this:
class HandlerManager {
    private Map<Key,Handler> map = new HashMap<Key,Handler>();
    private final Lock readLock;
    private final Lock writeLock;
    public HandlerManager() {
        ReadWriteLock lock = new ReentrantReadWriteLock();
        readLock = lock.readLock();
        writeLock = lock.writeLock();
    public Handler getHandler(Key key) {
        Handler handler = null;
        readLock.lock();
        try {
            handler = map.get(key);
        } finally {
            readLock.unlock();
        if (handler == null) {
            writeLock.lock();
            try {
                handler = map.get(key);
                if (handler == null) {
                    handler = new Handler();
                    map.put(key, handler);
            finally {
                writeLock.unlock();
        return handler;
}

Similar Messages

  • Best Practice for CTS_Project use in a Non-ChARM ECC6.0 System

    We are on ECC6.0 and do not leverage Solution Manager to any extent.  Over the years we have performed multiple technical upgrades but in many ways we are running our ECC6.0 solution using the same tools and approaches as we did back in R/3 3.1. 
    The future vision for us is to utilize CHARM to manage our ITIL-centric change process but we have to walk before we can run and are not yet ready to make that leap.  Currently we are just beginning to leverage CTS_Projects in ECC as a grouping tool for transports but are still heavily tied to Excel-based "implementation plans".  We would appreciate references or advice on best practices to follow with respect to the creation and use of the CTS_Projects in ECC.
    Some specific questions: 
    #1 Is there merit in creating new CTS Projects for support activities each year?  For example, we classify our support system changes as "Normal", "Emergency", and "Standard".  These correspond to changes deployed on a periodic schedule, priority one changes deployed as soon as they are ready, and changes that are deemed to be "pre-approved" as they are low risk. Is there a benefit to create a new CTS_Project each year e.g. "2012 Emergencies", "2013 Emergencies" etc. or should we just create a CTS_Project "Emergencies" which stays open forever and then use the export time stamp as a selection criteria when we want to see what was moved in which year?
    #2 We experienced significant system performance issues on export when we left the project intersections check on.  There are many OSS notes about performance of this tool but in the end we opted to turn off this check.  Does anyone use this functionality?  Any reocmmendations?
    Any other advice would be greatly appreciated.

    Hi,
    I created a project (JDeveloper) with local xsd-files and tried to delete and recreate them in the structure pane with references to a version on the application server. After reopening the project I deployed it successfully to the bpel server. The process is working fine, but in the structure pane there is no information about any of the xsds anymore and the payload in the variables there is an exception (problem building schema).
    How does bpel know where to look for the xsd-files and how does the mapping still work?
    This cannot be the way to do it correctly. Do I have a chance to rework an existing project or do I have to rebuild it from scratch in order to have all the references right?
    Thanks for any clue.
    Bette

  • Best practice for the use of reserved words

    Hi,
    What is the best practice to observe for using reserved words as column names.
    For example if I insisted on using the word comment for a column name by doing the following:
    CREATE TABLE ...
    "COMMENT" VARCHAR2(4000),
    What impact down the track could I expect and what problems should I be aware of when doing something like this?
    Thank You
    Ben

    Hi, Ben,
    Benton wrote:
    Hi,
    What is the best practice to observe for using reserved words as column names.Sybrand is right (as usual): the best practice is not to use them
    For example if I insisted on using the word comment for a column name by doing the following:
    CREATE TABLE ...
    "COMMENT" VARCHAR2(4000),
    What impact down the track could I expect and what problems should I be aware of when doing something like this?Using reserved words as identifiers is asking for trouble. You can expect to get what you ask for.
    Whatever benefits you may get from naming the column COMMENT rather than, say, CMNT or EMP_COMMENT (if the table is called EMP) will be insignificant compared to the extra debugging you will certainly need.

  • Best practice for development using REST API - OData

    Hi All, I am new to REST. I am a developer who works mostly in server-side code using Visual Studio. Now that Microsoft is advocating to write code using REST API instead of server-side code or client side object model, I am trying to use REST API.
    I googled and most of the example shows to write a code and put it on Content Editor/Script Editor. How to organize code and deploy to the staging/production in this scenario? Is there any Best Practice or example around this?
    Regards,
    Khushi

    If you are writing code in aspx or cs it does not mean that you need to deploy it in the SharePoint server, it could be any other application running from your remote server. What I mean it you can use C# & Rest API to connect to SharePoint server.
    REST API in SharePoint 2013 provides the developers with a simple standardized method of retrieving information from SharePoint and it can be used from any technology that is capable of sending standard HTTP requests.
    Refer to the following blog that provide your more details about comparison of the major features of these programming choices/
    http://msdn.microsoft.com/en-us/library/jj164060.aspx#RESTODataA
    http://dlr2008.wordpress.com/2013/10/31/sharepoint-2013-rest-api-the-c-connection-part-1-using-system-net-http-httpclient/
    Hope this helps
    --Cheers

  • SqlCeConnection in CE 4.0: best practices for desktop use?

    I am using SQL Server CE 4.0 in a WinForms desktop application and was wondering what are the recommended practices for using SqlCeConnection in this context. I noticed some older threads on the topic however some of them talk mostly about mobile or are
    from a long time ago
    1. Should a new SqlCeConnection be created every time the DB is accessed or is it better to have on SqlCeConnection open and shared through the entire application?  My application can make frequent writes to the DB and when this happens I notice a noticeable
    UI lag if a new SqlCeConnection is created for which DB access.
    2. Can SqlCeConnection instances be shared across threads? On occasion my application performs DB reads in a background thread. Can I use the same SqlCeConnection instance from different threads?
    3. Are there any additional steps needed to ensure multi-thread safety when multiple threads can access the DB simultaneously when SQL Server CE is deployed in embedded mode? When I create a new SqlCeConnection for each DB access I ran into a few crashes
    and Monitor exceptions, possibly when multiple threads are accessing the same database.
    I am using SQL Server CE 4.0 embedded in a WinForms 2.0 Windows desktop application (non-mobile).  Any advice would be appreciated.

    You must use seperate SqlCeConnection etc object per thread, as these objects are not thread safe.
    I recommend opening the database on the main thread, and keep this connection unused and open for the lifetime of the app to keep the database file and engine "warm".
    Please mark as answer, if this was it. Visit my SQL Server Compact blog http://erikej.blogspot.com

  • Firewall what is best practice for home use?

    Hi (from France) and thanks in advance.
    I want to activate firewall but don't know which setting to choose for the right mix of security/ease of use. My Imac connected by ethernet to Dartybox (router) and sharing internet access with my wife's Macbook pro via wifi .

    simonfromfra wrote:
    The 'dartybox' router has a very poor security rating - so my reading tells me, and is the easiest of all French internet  "out of the box all in one" connections to hjack (crack codes well documented)... hence my desire for second layer protection.
    Take a look at: IceFloor
    IceFloor is not a firewall. Your Mac already features three built-in firewalls:
    • ALF
    • PF
    • IPFW
    ALF is an application firewall, while both PF and IPFW are network firewalls.
    ALF can be configured using System Preferences “Security” pane.
    PF and IPFW do not have a default graphic interface shipped with OS X, so they can be configured only using the shell terminal. Using the terminal is the favourite choice by most system administrators.
    Since Mac OS X 10.7 IPFW has been deprecated. PF is the new default OS X network firewall. To configure PF without using the shell terminal we must use a graphic interface (frontend) from third party software makers.
    IceFloor is a graphic frontend for PF.
    It features a lot of advanced tools and options that will let you set up a very complex PF ruleset.
    IceFloor needs OS X 10.7 or newer.
    Bandwidth management with PF/Dummynet is supported on OS X 10.8 and newer.
    PF ruleset created with IceFloor 2.0 has been tested on:
    OS X 10.7 OS X 10.8 OS X 10.9 iOS 5
    iOS 6 FreeBSD 9 OpenBSD 4.3
    We developed also a limited version of IceFloor named PFLists.
    PFLists is a free and open source basic PF frontend with the same requirements as IceFloor 2.

  • Best Practices for dashboards using Query Browser

    Hi,
    As aligned with business requirement, dashboards are using Query browser to fetch data from universes built on SSAS cubes. The issue here is it takes around a minute to initially load the dashboard which is very long as per requirement. Can I find any document or basic points to be taken care of, on improving performance for these dashboards.There are around 30 Queries being used.(cant integrate the queries to decrease the number). Also , using ranking logics at excel level, does this affect the performance?? (All vlookups and "should not be used" formulaes have been omitted)
    Thanks in advance.

    Hi Aarti,
    Check the thread http://scn.sap.com/thread/3482541.
    Any functions used in Excel level like ranking,vlookp etc affects the performance.
    Also check the components you have used in Dashboard as some of them affects the performance.
    Regards,
    JC

  • Best Practice for Use of ABAP in Customizing SRM and/or CRM

    I was wondering if there is a document that defines best practices for the use of ABAP with the installation and customization of SRM and/or CRM.   Such as amount of ABAP coding typically required, and best practices around the use of ABAP for customization and configuration.
    Thanks.

    Hi, Johnson
    Sorry, Please don't mind, you are not at right place to ask the Question like this
    Please read "The Forum Rules of Engagement" before posting!  HOT NEWS!!
    Thanks and Regards,
    Faisal

  • Best Practices for Using Photoshop (and Computing in General)

    I've been seeing some threads that lead me to realize that not everyone knows the best practices for doing Photoshop on a computer, and in doing conscientious computing in general.  I thought it might be a good idea for those of us with some exprience to contribute and discuss best practices for making the Photoshop and computing experience more reliable and enjoyable.
    It'd be great if everyone would contribute their ideas, and especially their personal experience.
    Here are some of my thoughts on data integrity (this shouldn't be the only subject of this thread):
    Consider paying more for good hardware. Computers have almost become commodities, and price shopping abounds, but there are some areas where spending a few dollars more can be beneficial.  For example, the difference in price between a top-of-the-line high performance enterprise class hard drive and the cheapest model around with, say, a 1 TB capacity is less than a hundred bucks!  Disk drives do fail!  They're not all created equal.  What would it cost you in aggravation and time to lose your data?  Imagine it happening at the worst possible time, because that's exactly when failures occur.
    Use an Uninterruptable Power Supply (UPS).  Unexpected power outages are TERRIBLE for both computer software and hardware.  Lost files and burned out hardware are a possibility.  A UPS that will power the computer and monitor can be found at the local high tech store and doesn't cost much.  The modern ones will even communicate with the computer via USB to perform an orderly shutdown if the power failure goes on too long for the batteries to keep going.  Again, how much is it worth to you to have a computer outage and loss of data?
    Work locally, copy files elsewhere.  Photoshop likes to be run on files on the local hard drive(s).  If you are working in an environment where you have networking, rather than opening a file right off the network, then saving it back there, consider copying the file to your local hard drive then working on it there.  This way an unexpected network outage or error won't cause you to lose work.
    Never save over your original files.  You may have a library of original images you have captured with your camera or created.  Sometimes these are in formats that can be re-saved.  If you're going to work on one of those files (e.g., to prepare it for some use, such as printing), and it's a file type that can be overwritten (e.g., JPEG), as soon as you open the file save the document in another location, e.g., in Photoshop .psd format.
    Save your master files in several places.  While you are working in Photoshop, especially if you've done a lot of work on one document, remember to save your work regularly, and you may want to save it in several different places (or copy the file after you have saved it to a backup folder, or save it in a version management system).  Things can go wrong and it's nice to be able to go back to a prior saved version without losing too much work.
    Make Backups.  Back up your computer files, including your Photoshop work, ideally to external media.  Windows now ships with a quite good backup system, and external USB drives with surprisingly high capacity (e.g., Western Digital MyBook) are very inexpensive.  The external drives aren't that fast, but a backup you've set up to run late at night can finish by morning, and if/when you have a failure or loss of data.  And if you're really concerned with backup integrity, you can unplug an external drive and take it to another location.
    This stuff is kind of "motherhood and apple pie" but it's worth getting the word out I think.
    Your ideas?
    -Noel

    APC Back-UPS XS 1300.  $169.99 at Best Buy.
    Our power outages here are usually only a few seconds; this should give my server about 20 or 25 minutes run-time.
    I'm setting up the PowerChute software now to shut down the computer when 5 minutes of power is left.  The load with the monitor sleeping is 171 watts.
    This has surge protection and other nice features as well.
    -Noel

  • What are the best practices for using the enhancement framework?

    Hello enhancement framework experts,
    Recently, my company upgraded to SAP NW 7.1 EhP6.  This presents us with the capability to use the enhancement framework.
    A couple of senior programmers were asked to deliver a guideline for use of the framework.  They published the following statement:
    "SAP does not guarantee the validity of the enhancement points in future releases/versions. As a result, any implemented enhancement points may require significant work during upgrades. So, enhancement points should essentially be used as an alternative to core modifications, which is a rare scenario.".
    I am looking for confirmation or contradiction to the statement  "SAP does not guarantee the validity of enhancement points in future releases/versions..." .  Is this a true statement for both implicit and explicit enhancement points?
    Is the impact of activated explicit and implicit enhancements much greater to an SAP upgrade than BAdi's and user exits?
    Is there any SAP published guidelines/best practices for use of the enhancement framework?
    Thank you,
    Kimberly
    Edited by: Kimberly Carmack on Aug 11, 2011 5:31 PM

    Found an article that answers this question quite well:
    [How to Get the Most From the Enhancement and Switch Framework as a Customer or Partner - Tips from the Experts|http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/c0f0373e-a915-2e10-6e88-d4de0c725ab3]
    Thank you Thomas Weiss!

  • JSF - Best Practice For Using Managed Bean

    I want to discuss what is the best practice for managed bean usage, especially using session scope or request scope to build database driven pages
    ---- Session Bean ----
    - In the book Core Java Server Faces, the author mentioned that most of the cases session bean should be used, unless the processing is passed on to other handler. Since JSF can store the state on client side, i think storing everything in session is not a big memory concern. (can some expert confirm this is true?) Session objects are easy to manage and states can be shared across the pages. It can make programming easy.
    In the case of a page binded to a resultset, the bean usually helds a java.util.List object for the result, which is intialized in the constructor by query the database first. However, this approach has a problem: when user navigates to other page and comes back, the data is not refreshed. You can of course solve the problem by issuing query everytime in your getXXX method. But you need to be very careful that you don't bind this XXX property too many times. In the case of querying in getXXX, setXXX is also tricky as you don't have a member to set. You usually don't want to persist the resultset changes in the setXXX as the changes may not be final, in stead, you want to handle in the actionlistener (like a save(actionevent)).
    I would glad to see your thought on this.
    --- Request Bean ---
    request bean is initialized everytime a reuqest is made. It sometimes drove me nuts because JSF seems not to be every consistent in updating model values. Suppose you have a page showing parent-children a list of records from database, and you also allow user to change directly on the children. if I hbind the parent to a bean called #{Parent} and you bind the children to ADF table (value="#{Parent.children}" var="rowValue". If I set Parent as a request scope, the setChildren method is never called when I submit the form. Not sure if this is just for ADF or it is JSF problem. But if you change the bean to session scope, everything works fine.
    I believe JSF doesn't update the bindings for all component attributes. It only update the input component value binding. Some one please verify this is true.
    In many cases, i found request bean is very hard to work with if there are lots of updates. (I have lots of trouble with update the binding value for rendered attributes).
    However, request bean is working fine for read only pages and simple binded forms. It definitely frees up memory quicker than session bean.
    ----- any comments or opinions are welcome!!! ------

    I think it should be either Option 2 or Option 3.
    Option 2 would be necessary if the bean data depends on some request parameters.
    (Example: Getting customer bean for a particular customer id)
    Otherwise Option 3 seems the reasonable approach.
    But, I am also pondering on this issue. The above are just my initial thoughts.

  • Best practice for using messaging in medium to large cluster

    What is the best practice for using messaging in medium to large cluster In a system where all the clients need to receive all the messages and some of the messages can be really big (a few megabytes and maybe more)
    I will be glad to hear any suggestion or to learn from others experience.
    Shimi

    publish/subscribe, right?
    lots of subscribers, big messages == lots of network traffic.
    it's a wide open question, no?
    %

  • Best Practice for using multiple models

    Hi Buddies,
         Can u tell me the best practices for using multiple models in single WD application?
        Means --> I am using 3 RFCs on single application for my function. Each time i am importing that RFC model under
        WD --->Models and i did model binding seperately to Component Controller. Is this is the right way to impliment  multiple            models  in single application ?

    It very much depends on your design, but One RFC per model is definitely a no no.
    Refer to this document to understand how should you use the model in most efficient way.
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/705f2b2e-e77d-2b10-de8a-95f37f4c7022?quicklink=events&overridelayout=true
    Thanks
    Prashant

  • Best Practice for Using Static Data in PDPs or Project Plan

    Hi There,
    I want to make custom reports using PDPs & Project Plan data.
    What is the Best Practice for using "Static/Random Data" (which is not available in MS Project 2013 columns) in PDPs & MS Project 2013?
    Should I add that data in Custom Field (in MS Project 2013) or make PDPs?
    Thanks,
    EPM Consultant
    Noman Sohail

    Hi Dale,
    I have a Project Level custom field "Supervisor Name" that is used for Project Information.
    For the purpose of viewing that "Project Level custom field Data" in
    Project views , I have made Task Level custom field
    "SupName" and used Formula:
    [SupName] = [Supervisor Name]
    That shows Supervisor Name in Schedule.aspx
    ============
    Question: I want that Project Level custom field "Supervisor Name" in
    My Work views (Tasks.aspx).
    The field is enabled in Task.aspx BUT Data is not present / blank column.
    How can I get the data in "My Work views" ?
    Noman Sohail

  • Best Practice for using UML in JDeveloper 11g

    Hi,
    We are embarking upon a big program that involves development of a Webcenter 11g based Portal. We will be using JDeveloper for doing the development work. We are investigating whether we can use JDeveloper for doing the design work too. Towards that we would like to know if there are any best practices documented around using JDeveloper's UML capabilities in a Webcenter 11g Portal delivery activity that spans across several sprint teams and involves delivering an application that could involve several hundreds of java classes ? If so, can you please share the same / provide pointers to the same ?
    We are keen on using class diagrams and sequence diagrams for the design work.
    We will be using JDeveloper 11.1.1.5.0.
    Many thanks!
    Best Regards,
    Ramesh

    Check this to get an idea of UML support in JDeveloper:
    http://download.oracle.com/docs/cd/E18941_01/tutorials/jdtut_11r2_81/jdtut_11r2_81_1.html
    Thanks,
    Navaneeth

Maybe you are looking for

  • Download to application server using job open/close

    Hello people, Currently I am using open/close dataset to download to the application server automatically. What I do here is submit a program execute in background when the report is done the report is automatically downloaded to the application serv

  • Downloading a video

    So to give some background first: I personally have a Nexus 7. Our family has a shared iPad. I downloaded a video on my N7, then decided I wanted to also download it on the iPad so I could watch it on the bigger screen. It was a video that I download

  • IDVD 5 unexpectely quits!!

    Since I upgraded to IDVD 5 and also updated to last Apple update, I face many problems using Idvd. When I try to use Idvd through imovie the idvd quits! when I try to use the new feature of doing a dvd movie direcly from my camera it quits again! wha

  • IPhoto prints photos in grayscale. Other apps print them in color.

    If I print photos from iPhoto to a color printer (HP Photosmart 3300), they print as grayscale. They show as color in the print dialogs and in print preview, but they physically print as grayscale. If I print the same photos using Photoshop or Safari

  • First time mp3 player user and zen owner

    just bought a orange zen micro on ebay this weekend after researchin the zen and mini......ended up lookin at subcribtion music services to weight my choice.....specificall napster to go.....anyway im glad to see creative has this disscussion board..