Code example for ConcurrentHashMap

0
package com.taobao.oceanbase.network; 
 
import java.net.SocketAddress; 
import java.util.concurrent.ConcurrentHashMap; 
import java.util.concurrent.ConcurrentMap; 
import java.util.concurrent.TimeUnit; 
import java.util.concurrent.locks.ReentrantLock; 
 
public abstract class SessionFactory { 
 
	private ConcurrentMap<SocketAddress, Session> cache = new ConcurrentHashMap<SocketAddress, Session>();
 
	private ReentrantLock lock = new ReentrantLock();
 
	public Session getSession(Server server, SocketAddress address,
			int timeout, TimeUnit unit) {
		Session session = cache.get(address);
		if (session != null)
			return session;
		lock.lock();
		try { 
			session = cache.get(address);
			if (session == null) {
				session = getNewSession(server, address, timeout, unit);
				cache.put(address, session);