Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 Web 应用程序中使用 CommonsHttpSolrServer。在多个请求上重用 CommonsHttpSolrServer 是否安全,或者我应该为每个请求实例化一个新对象?在 API 文档中找不到答案。
根据文档和源注释,SolrJ 是线程安全的。
但是,更新 solr 时要小心。根据这篇文章,事务是按实例实现的,而不是按队列实现的。这意味着每个线程都没有自己的隔离事务可以使用。回滚会将每次调用(不管发起线程)回滚到最后一次提交。
总的来说,这意味着您应该可以安全地使用任意数量的线程进行查询(使用相同的 CommonsHttpSolrServer)。但是,如果您希望利用回滚,则需要确保一次只有一个线程在更新您的 solr 实例(无论对象分布如何)。