Lucene QueryParser in multiple threads: sync or create new ones every time?

I have a web application in which users submit requests to the Lucene index. Requests are parsed by Lucene QueryParser. I have learned that QueryParserit is not thread safe.

Is it better to use one instance QueryParserand synchronize it when called with its method parse()? Or is it better to build a new instance for each request? (Or am I better off serving pool QueryParsers?)

I know that in general such questions depend on the details and require profiling, but perhaps one of them can finally say “ QueryParserextremely inexpensive / expensive to build”?

+5
source share
1 answer

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

+6
source

All Articles