SessionContextUtil

package com.xinhuanet.cloudDesk.util;

import javax.servlet.http.HttpSession;
import java.util.HashMap;

public class SessionContextUtil {
	private static SessionContextUtil instance;
	private HashMap mymap;

	private SessionContextUtil() {
		mymap = new HashMap();
	}

	public static SessionContextUtil getInstance() {
		if (instance == null) {
			instance = new SessionContextUtil();
		}
		return instance;
	}

	public synchronized void AddSession(HttpSession session) {
		if (session != null) {
			mymap.put(session.getId(), session);
		}
	}

	public synchronized void DelSession(HttpSession session) {
		if (session != null) {
			mymap.remove(session.getId());
		}
	}

	public synchronized HttpSession getSession(String session_id) {
		if (session_id == null)
			return null;
		return (HttpSession) mymap.get(session_id);
	}

}

你可能感兴趣的:(session)