package com.pool;
import java.util.HashMap;
import java.util.Map;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
public class SolrClientPool {
private static final int TIME_OUT = 30000;
private static volatile Map<String, HttpSolrServer> solrServerMap = new HashMap<>();
public static HttpSolrServer getInstance(String baseUrl) {
HttpSolrServer httpSolrServer = solrServerMap.get(baseUrl);
if (httpSolrServer == null) {
synchronized (solrServerMap) {
httpSolrServer = solrServerMap.get(baseUrl);
if (httpSolrServer == null) {
httpSolrServer = new HttpSolrServer(baseUrl);
httpSolrServer.setMaxTotalConnections(100);
httpSolrServer.setDefaultMaxConnectionsPerHost(100);
httpSolrServer.setConnectionTimeout(TIME_OUT);
httpSolrServer.setSoTimeout(TIME_OUT);
solrServerMap.put(baseUrl, httpSolrServer);
}
}
}
return httpSolrServer;
}
}