IDEMPIERE-1044 Load testing. Fixed synchronization issue for m_instances.

This commit is contained in:
Heng Sin Low 2013-06-12 14:22:17 +08:00
parent 0d3d95ecbc
commit 1d1782a02c
1 changed files with 17 additions and 10 deletions

View File

@ -103,7 +103,7 @@ public class CacheMgt
* @param instance Cache
* @return true if removed
*/
public boolean unregister (CacheInterface instance)
public synchronized boolean unregister (CacheInterface instance)
{
if (instance == null)
return false;
@ -223,9 +223,9 @@ public class CacheMgt
{
int counter = 0;
int total = 0;
for (int i = 0; i < m_instances.size(); i++)
CacheInterface[] instances = getInstancesAsArray();
for (CacheInterface stored : instances)
{
CacheInterface stored = (CacheInterface)m_instances.get(i);
if (stored != null && stored.size() > 0)
{
if (log.isLoggable(Level.FINE)) log.fine(stored.toString());
@ -236,6 +236,13 @@ public class CacheMgt
if (log.isLoggable(Level.FINE)) log.fine("#" + counter + " (" + total + ")");
return total;
}
/**
* @return
*/
protected synchronized CacheInterface[] getInstancesAsArray() {
return m_instances.toArray(new CacheInterface[0]);
}
/**
* Reset local Cache
@ -252,9 +259,9 @@ public class CacheMgt
//
int counter = 0;
int total = 0;
for (int i = 0; i < m_instances.size(); i++)
CacheInterface[] instances = getInstancesAsArray();
for (CacheInterface stored : instances)
{
CacheInterface stored = (CacheInterface)m_instances.get(i);
if (stored != null && stored instanceof CCache)
{
CCache<?, ?> cc = (CCache<?, ?>)stored;
@ -287,9 +294,9 @@ public class CacheMgt
if (!m_tableNames.contains(tableName))
return;
//
for (int i = 0; i < m_instances.size(); i++)
CacheInterface[] instances = getInstancesAsArray();
for (CacheInterface stored : instances)
{
CacheInterface stored = (CacheInterface)m_instances.get(i);
if (stored != null && stored instanceof CCache)
{
CCache<?, ?> cc = (CCache<?, ?>)stored;
@ -308,11 +315,11 @@ public class CacheMgt
* @return count
*/
public int getElementCount()
{
{
int total = 0;
for (int i = 0; i < m_instances.size(); i++)
CacheInterface[] instances = getInstancesAsArray();
for (CacheInterface stored : instances)
{
CacheInterface stored = (CacheInterface)m_instances.get(i);
if (stored != null && stored.size() > 0)
{
if (log.isLoggable(Level.FINE)) log.fine(stored.toString());