From f8fa9777cbdb0b2d0c2dd8b85f511d28ae3565cf Mon Sep 17 00:00:00 2001 From: Jacopo Cappellato Date: Tue, 29 May 2012 10:19:21 +0000 Subject: [PATCH] Improved code that manages the cache: * removed unnecessary synchronization * protected the UtilCache object (static field) by making it private and final git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1343646 13f79535-47bb-0310-9956-ffa450edef68 --- .../pos/src/org/ofbiz/pos/screen/PosDialog.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/specialpurpose/pos/src/org/ofbiz/pos/screen/PosDialog.java b/specialpurpose/pos/src/org/ofbiz/pos/screen/PosDialog.java index af0e79e47d..8cb8791a37 100644 --- a/specialpurpose/pos/src/org/ofbiz/pos/screen/PosDialog.java +++ b/specialpurpose/pos/src/org/ofbiz/pos/screen/PosDialog.java @@ -48,7 +48,7 @@ import org.ofbiz.base.util.cache.UtilCache; public class PosDialog { public static final String module = PosDialog.class.getName(); - protected static UtilCache instances = UtilCache.createUtilCache("pos.Dialogs", 0, 0); + private static final UtilCache instances = UtilCache.createUtilCache("pos.Dialogs", 0, 0); protected final Frame clientFrame = XProjectManager.getCurrentProject().getAppFrame(); protected final Window appWindow = XProjectManager.getCurrentProject().getAppWindow(); @@ -71,14 +71,7 @@ public class PosDialog { public static PosDialog getInstance(XPage page, boolean modal, int padding) { PosDialog dialog = (PosDialog) instances.get(page); if (dialog == null) { - synchronized(PosDialog.class) { - dialog = (PosDialog) instances.get(page); - - if (dialog == null) { - dialog = new PosDialog(page, modal, padding); - instances.put(page, dialog); - } - } + dialog = instances.putIfAbsentAndGet(page, new PosDialog(page, modal, padding)); } dialog.modal = modal;