java 通过map实现循环控制

public Object cycle(){

private Map<String, Long> userTicks = new HashMap<String, Long>();

String memberId = member.getId();

if (userTicks.containsKey(memberId)) {
Long tick = userTicks.get(memberId);
if (System.currentTimeMillis() - tick < 1 * 1000) {
return new APIResult(GlobalConstantsUtil.GENERAL_ERROR, "请勿频繁操作");
}
}

/**

*代码逻辑

*

/

userTicks.put(memberId, System.currentTimeMillis());

return APIResult.createSuccess();

}

猜你喜欢

转载自www.cnblogs.com/qqzhulu/p/10252923.html