Explanation of SolrNet connection

牧云@^-^@ 提交于 2019-12-10 14:13:55

问题


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:


  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.



来源:https://stackoverflow.com/questions/6830623/explanation-of-solrnet-connection

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!