Thanks for your reply!

I do understand your explaination, but another question accurs, When I
create CloudSolrServer Connection by singleton pattern like this, and I
call shutdown, but it's OK. the solr version is 4.9.0. that's why?

    public synchronized static CloudSolrServer getSolrCloudReadServer() {
        if (reviewSolrCloudServer == null) {
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, 10000);
        params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, 500);
        HttpClient client = HttpClientUtil.createClient(params);
        LBHttpSolrServer lbServer = new LBHttpSolrServer(client);

lbServer.setConnectionTimeout(ReviewProperties.getCloudConnectionTimeOut());
        lbServer.setSoTimeout(ReviewProperties.getCloudSoTimeOut());

        reviewSolrCloudServer = new
CloudSolrServer(ReviewProperties.getZkHost(),lbServer);
        reviewSolrCloudServer.setDefaultCollection("commodityReview");

reviewSolrCloudServer.setZkClientTimeout(ReviewProperties.getZkClientTimeout());

reviewSolrCloudServer.setZkConnectTimeout(ReviewProperties.getZkConnectTimeout());
        reviewSolrCloudServer.connect();
        }
        return reviewSolrCloudServer;
    }


2016-07-02 14:22 GMT+08:00 Shawn Heisey <apa...@elyograg.org>:

> On 7/1/2016 10:59 PM, Kent Mu wrote:
> > solr version: 4.9.0 I create and get a HttpSolrServer connection by
> > singleton pattern. I find the method of "shutdown" in solrj API, so I
> > decided to use "shutdown" to release resources, but I got the error as
> > below, It is due to singleton pattern?
>
> If you call shutdown, that client object can no longer be used.  You
> will need to make a new one.
>
> The expected usage pattern for the client object is that you will create
> one object when the program starts and use it for all threads until the
> program exits.  Whether or not to use the singleton pattern for that is
> up to you.  Usually the only time you would call shutdown is just before
> program exit ... but if the program is exiting, shutdown isn't really
> necessary.
>
> If you are in a situation where client objects are being regularly
> created, then you would want to do shutdown on each of them when you are
> finished so you don't have a resource leak.  Creating many client
> objects is not recommended.
>
> Thanks,
> Shawn
>
>

Reply via email to