对同一个帐号如果同时存在两个或以上的线程同时缴费,且EJB采用均衡机制部署在不同主机上时(内存不同,存在两个TestControl实例)缴费不正确。
这个时候导致可以同时对同一个帐户进行缴费,造成读脏数据的问题。
改变原来在内存中注册的机制,以下是原来的处理方式public class TestControl extends Object
{
private static TransControl instance = null;
private FastHashMap transMap = null;
private TransControl()
{
transMap = new FastHashMap();
}
public static synchronized TestControl getInstance()
{
if(instance == null)
{
instance = new TestControl();
}
return instance;
}
public boolean addMap(BigDecimal xx) throws XXException
{
try
{
if(null == transMap.get(xx))
{
transMap.put(xx, xx);
return true;
}
else
{
throw new XXException(BBBBB);
}
}
catch(XXException e)
{
throw e;
}
catch(Exception e)
{
throw new XXException(e);
}
}
public void removeMap(BigDecimal xx) throws XXException
{
try
{
if(null != transMap)
{
transMap.remove(xx);
}
}
catch(Exception e)
{
throw new XXException(e);
}
}
}有什么好的法子改变这种现象,请大家赐教.
这个时候导致可以同时对同一个帐户进行缴费,造成读脏数据的问题。
改变原来在内存中注册的机制,以下是原来的处理方式public class TestControl extends Object
{
private static TransControl instance = null;
private FastHashMap transMap = null;
private TransControl()
{
transMap = new FastHashMap();
}
public static synchronized TestControl getInstance()
{
if(instance == null)
{
instance = new TestControl();
}
return instance;
}
public boolean addMap(BigDecimal xx) throws XXException
{
try
{
if(null == transMap.get(xx))
{
transMap.put(xx, xx);
return true;
}
else
{
throw new XXException(BBBBB);
}
}
catch(XXException e)
{
throw e;
}
catch(Exception e)
{
throw new XXException(e);
}
}
public void removeMap(BigDecimal xx) throws XXException
{
try
{
if(null != transMap)
{
transMap.remove(xx);
}
}
catch(Exception e)
{
throw new XXException(e);
}
}
}有什么好的法子改变这种现象,请大家赐教.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货