SolrNet连接释 [英] Explaination of SolrNet connection

查看:169
本文介绍了SolrNet连接释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么SolrNet连接的容器保持静态的?这是一个非常大的错误,因为当,在我们的应用中,我们发出异步请求我们的应用程序,SolrNet异常行为。我怎样才能避免SolrNet?



  P级
{
静态无效M(字符串[这个问题]一)
{
线程t =新主题(委托()
{
F1();
});
线T1 =新主题(委托()
{
F2();
});

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

静态无效F1()
{
Startup.Init<&文件GT;(新SolrNet.Impl.SolrPostConnection(HTTP://本地主机:8983 / solr3 /));
ISolrOperations<&文件GT; solrOperations2 = ServiceLocator.Current.GetInstance< ISolrOperations<文件>>();
}

静态无效F2()
{
Startup.Init<&文件GT;(新SolrNet.Impl.SolrPostConnection(HTTP://本地主机:8983 / solr1 /));
ISolrOperations<&文件GT; solrOperations2 = ServiceLocator.Current.GetInstance< ISolrOperations<文件>>();
}
}


解决方案

  1. 在维基,内置容器(启动)目前仅限于访问多个内核/实例与不同类型的映射。如果您想了解这个更多的灵活性,无论是切换到温莎/ StructureMap / Autofac,或的帮助实现这个
    功能


  2. 在注册内置容器可能不是线程安全的,因为你已经发现,但你获得通过注册/在不同的线程初始化SolrNet什么。只是将所有初始化一个线程,当你做solr.Query(...)或solr.Add(...),它的是实际的繁重的工作,执行的线程安全的。



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.

这篇关于SolrNet连接释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆