IDEMPIERE-3622 MRecentItem is not thread safe

This commit is contained in:
Heng Sin Low 2018-01-19 13:59:24 +08:00
parent dc373fbb4e
commit af17364314
1 changed files with 14 additions and 8 deletions

View File

@ -64,9 +64,11 @@ public class MRecentItem extends X_AD_RecentItem
{ {
super (ctx, AD_RecentItem_ID, trxName); super (ctx, AD_RecentItem_ID, trxName);
if (AD_RecentItem_ID > 0) { if (AD_RecentItem_ID > 0) {
Integer key = new Integer (AD_RecentItem_ID); synchronized (MRecentItem.class) {
if (!s_cache.containsKey(key)) Integer key = new Integer (AD_RecentItem_ID);
s_cache.put (key, this); if (!s_cache.containsKey(key))
s_cache.put (key, this);
}
} }
} // MRecentItem } // MRecentItem
@ -85,8 +87,10 @@ public class MRecentItem extends X_AD_RecentItem
} catch (SQLException e) { } catch (SQLException e) {
throw new AdempiereException(e); throw new AdempiereException(e);
} }
if (key != null && !s_cache.containsKey(key)) synchronized (MRecentItem.class) {
s_cache.put (key, this); if (key != null && !s_cache.containsKey(key))
s_cache.put (key, this);
}
} // MRecentItem } // MRecentItem
/** /**
@ -95,7 +99,7 @@ public class MRecentItem extends X_AD_RecentItem
* @param AD_RecentItem_ID id * @param AD_RecentItem_ID id
* @return recent item * @return recent item
*/ */
public static MRecentItem get (Properties ctx, int AD_RecentItem_ID) public static synchronized MRecentItem get (Properties ctx, int AD_RecentItem_ID)
{ {
Integer ii = new Integer (AD_RecentItem_ID); Integer ii = new Integer (AD_RecentItem_ID);
MRecentItem ri = (MRecentItem)s_cache.get(ii); MRecentItem ri = (MRecentItem)s_cache.get(ii);
@ -111,7 +115,7 @@ public class MRecentItem extends X_AD_RecentItem
* @param Record_ID recordID * @param Record_ID recordID
* @return recent item * @return recent item
*/ */
public static MRecentItem get (Properties ctx, int AD_Table_ID, int Record_ID, int AD_User_ID) public static synchronized MRecentItem get (Properties ctx, int AD_Table_ID, int Record_ID, int AD_User_ID)
{ {
Iterator<MRecentItem> it = s_cache.values().iterator(); Iterator<MRecentItem> it = s_cache.values().iterator();
while (it.hasNext()) while (it.hasNext())
@ -262,7 +266,9 @@ public class MRecentItem extends X_AD_RecentItem
@Override @Override
public boolean delete(boolean force) { public boolean delete(boolean force) {
Integer ii = new Integer (getAD_RecentItem_ID()); Integer ii = new Integer (getAD_RecentItem_ID());
s_cache.remove(ii); synchronized (MRecentItem.class) {
s_cache.remove(ii);
}
return super.delete(force); return super.delete(force);
} }