SolrJ线程安全 [英] SolrJ Thread Safety

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

问题描述

我在Web应用程序中使用CommonsHttpSolrServer。在多个请求上重用CommonsHttpSolrServer是否安全,还是应该为每个请求实例化一个新对象?无法在API文档中找到答案。

I am using CommonsHttpSolrServer in a Web Application. Is it safe to reuse the CommonsHttpSolrServer over multiple requests or should I instantiate a new object for each request? Could not find the answer in the API docs.

推荐答案

根据文档和源代码注释,SolrJ是线程安全的。

According to the documentation and the source comments, SolrJ is thread safe.

但是,小心的时候要小心你更新solr。根据这篇文章,事务是按实例实现的,而不是每个队列实现的。这意味着每个线程都没有自己的孤立事务来处理。回滚将回滚每次调用(无论原始线程)到最后一次提交。

However, be careful when you update solr. According to this post, the transactions are implemented per instance, not per queue. This means that each thread does not have it's own isolated transaction to work with. Rollback will rollback every call (regardless of originating thread) to the last commit.

总的来说,这意味着您应该可以安全地查询(使用相同的CommonsHttpSolrServer)as as很多线程你喜欢。但是,如果您希望利用回滚,则需要确保一次只有一个线程更新您的solr实例(无论对象分发如何)。

Overall, this means that you should be safe to query (using the same CommonsHttpSolrServer) with as many threads as you like. However, if you wish to take advantage of rollback, you will need to ensure only one thread is updating your solr instance at a time (regardless of object distribution).

这篇关于SolrJ线程安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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