1. 程式人生 > >java 通過map實現循環控制

java 通過map實現循環控制

cycle ons eat hash shm java 頻繁 general create

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();

}

java 通過map實現循環控制