1. 程式人生 > >java 通過map實現迴圈控制

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

}