import java.util.LinkedList; import java.util.concurrent.ConcurrentHashMap; class Session { static public ConcurrentHashMap sessions = new ConcurrentHashMap(); LinkedList msg = new LinkedList(); public static Session get(String s) { Session t = sessions.get(s); if (t==null) { t = new Session(); sessions.put(s, t); } return t; } public String handlePush() { synchronized (msg) { if (msg.isEmpty()) { try { msg.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } return msg.poll(); } } }