Closed jiangcaijun closed 4 years ago
com.creditease.gateway.service.impl包下的StatisticServiceImpl类的 increament方法,如下:
com.creditease.gateway.service.impl
StatisticServiceImpl
increament
/** * 计数操作 * * */ @Override public void increament(String counterName) { Integer value = map.get(counterName); if(value!=null) { Integer added = Integer.sum(value.intValue(), 1); map.put(counterName, added); }else { map.put(counterName, 1); } }
该方法会存在线程安全问题:在qps比较高的时候,最后统计出的误差确实比较大。 但是解决方案上,也不能贸然直接 atomicinteger,否则在qps高的时候,cas自旋也会耗时较久。
atomicinteger
已经修正使用LongAddr
com.creditease.gateway.service.impl
包下的StatisticServiceImpl
类的increament
方法,如下:该方法会存在线程安全问题:在qps比较高的时候,最后统计出的误差确实比较大。 但是解决方案上,也不能贸然直接
atomicinteger
,否则在qps高的时候,cas自旋也会耗时较久。