Lucene QueryParser in multiple threads: synchronize or construct new each time?

无人久伴 提交于 2019-12-22 06:49:05

问题


I have a web application where users submit queries to a Lucene index. The queries are parsed by a Lucene QueryParser. I learned the hard way that QueryParser is not thread-safe.

Is it better to use a single QueryParser instance, and synchronize on calls to its parse() method? Or is it better to construct a new instance for each query? (Or would I be better served by a pool of QueryParsers?)

I know that in general questions like this depend on the particulars and require profiling, but maybe someone out there can say definitively "QueryParsers are extremely inexpensive/expensive to construct"?


回答1:


Create a new one each time. These are lightweight objects and the JVM handles object creation and garbage collection very well. Definitely do not use an object pool.



来源:https://stackoverflow.com/questions/5525018/lucene-queryparser-in-multiple-threads-synchronize-or-construct-new-each-time

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