📄 session.java
字号:
package com.gctech.sms.sp.dwzb;import java.util.*;/** * 用户会话 * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: gctech</p> * @author lijz@gctech.com.cn * @version 1.0 */public class Session{ Map map = new HashMap(5); int ttl; private Date dateofExpiration = null; String sessionId = null; public Session(String id,int ttl) { this.sessionId = id; this.ttl = ttl; populate(); } private void populate() { if (ttl != 0) { dateofExpiration = new java.util.Date(); java.util.Calendar cal = java.util.Calendar.getInstance(); cal.setTime(dateofExpiration); cal.add(cal.MINUTE, ttl); dateofExpiration = cal.getTime(); } } /** * 更新存活时间 */ private void update() { this.populate(); } /** * 比较是否超期 * @param now * @return */ protected boolean isExpired(Date now) { // Remember if the minutes to live is zero then it lives forever! if (dateofExpiration != null) { // date of expiration is compared. if (dateofExpiration.before(now)) { return true; } else { return false; } } else // This means it lives forever! { return false; } } public String getSessionId() { return this.sessionId; } public Object getValue(String name) { update(); return map.get(name); } public void setValue(String name,Object o) { update(); map.put(name,o); } public void clear() { update(); map.clear(); } public int hashCode() { return sessionId.hashCode(); } public static void main(String[] args) {// Session session1 = new Session(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -