开发者

Explanation of SolrNet connection

Why is the container of the SolrNet connections kept static? This is a very big fault, as when, in our application, we send an asynchronous request to our application, SolrNet behaves abnormally. How I can avoid this issue in SolrNet?

class P
{
    static void M(string[] a)
    { 
        Thread t = new Thread(delegate()
        {
            f1();
        });
        Thread t1 = new Thread(delegate()
        {
            f2();
        });

        t.Start();
        t1.Start();
        t.Join();
        t1.Join();
    }

    static void f1()
    {
        Startup.Init<Doc>(new SolrNet.Impl.SolrPostConnection("http://localhost:8983/solr3/"));
        ISolrOperations<Doc> solrOperations2 = ServiceLocator.Current.GetInstance<ISolrOperations<Document>>(开发者_如何转开发);
    }

    static void f2()
    {
        Startup.Init<Doc>(new SolrNet.Impl.SolrPostConnection("http://localhost:8983/solr1/"));
        ISolrOperations<Doc> solrOperations2 = ServiceLocator.Current.GetInstance<ISolrOperations<Document>>();
    }
}


  1. As explained in the wiki, the built-in container (Startup) is currently limited to access multiple cores/instances with different mapped types. If you want more flexibility about this, either switch to Windsor / StructureMap / Autofac, or help implement this feature.

  2. Registrations in the built-in container may not be thread-safe as you have discovered, but you gain nothing by registering / initializing SolrNet in different threads. Just move all initialization to a single thread, the actual heavy work is performed when you do solr.Query(...) or solr.Add(...) which is thread-safe.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜