Solrの接続プール

パッケージcom.pool。

輸入java.util.HashMapを;
輸入java.util.Map;

輸入org.apache.solr.client.solrj.impl.HttpSolrServer;


パブリッククラスSolrClientPool {
    
    プライベート静的最終int型TIME_OUT = 30000。
    
    プライベート静的揮発地図<文字列、HttpSolrServer> solrServerMap =新しいHashMapの<>();
    
    パブリック静的HttpSolrServerのgetInstance(文字列baseUrlに){
        HttpSolrServer httpSolrServer = solrServerMap.get(baseUrlに)。
        (httpSolrServer == NULL){もし
            同期(solrServerMap){
                httpSolrServer = solrServerMap.get(baseUrlに)。
                IF(httpSolrServer == NULL){
                    httpSolrServer =新しいHttpSolrServer(baseUrlに)。
                    httpSolrServer.setMaxTotalConnections(100)。
                    httpSolrServer.setDefaultMaxConnectionsPerHost(100)。
                    httpSolrServer.setConnectionTimeout(TIME_OUT)。
                    httpSolrServer.setSoTimeout(TIME_OUT)。
                    solrServerMap.put(baseUrlに、httpSolrServer)。
                }
            }
        }
        
        httpSolrServerを返します。
    }    
}
 

おすすめ

転載: blog.csdn.net/John_Kry/article/details/88222018
おすすめ