You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by jh...@fibertel.com.ar on 2005/08/23 18:47:22 UTC

QueryParser not thread-safe

Hi! I've been having problems with lucene's QueryParser, apparently it is not thread-safe. 

That means I can't parse queries in threads where the queryparser object is created once and reused for each query. If I do, the resulting queries may have all kinds of weird problems, for example missing terms, duplicate terms, etc. 

I don't like the idea of creating a new queryparser for each query, so I am looking for alternatives. Any ideas?

Thanks!


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: QueryParser not thread-safe

Posted by jian chen <ch...@gmail.com>.
Right. My philosophy is that, make it work, then, make it better. 

Don't waste time on something that you are not sure if it would cause
performance problem.

Jian

On 8/23/05, Paul Elschot <pa...@xs4all.nl> wrote:
> On Tuesday 23 August 2005 19:01, Miles Barr wrote:
> > On Tue, 2005-08-23 at 13:47 -0300, jhandl@fibertel.com.ar wrote:
> > > Hi! I've been having problems with lucene's QueryParser, apparently it is
> not thread-safe.
> > >
> > > That means I can't parse queries in threads where the queryparser object
> is created once and reused for each query. If I do, the resulting queries may
> have all kinds of weird problems, for example missing terms, duplicate terms,
> etc.
> > >
> > > I don't like the idea of creating a new queryparser for each query, so I
> am looking for alternatives. Any ideas?
> >
> > Using a non-threadsafe object in a threaded environment is fairly
> > standard in Java, just wrap it in a synchronized block.
> >
> > If you don't want all threads waiting on one query parser, create a pool
> > of them.
> 
> Or use one parser per thread.
> 
> Regards,
> Paul Elschot
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: QueryParser not thread-safe

Posted by Paul Elschot <pa...@xs4all.nl>.
On Tuesday 23 August 2005 19:01, Miles Barr wrote:
> On Tue, 2005-08-23 at 13:47 -0300, jhandl@fibertel.com.ar wrote:
> > Hi! I've been having problems with lucene's QueryParser, apparently it is 
not thread-safe. 
> > 
> > That means I can't parse queries in threads where the queryparser object 
is created once and reused for each query. If I do, the resulting queries may 
have all kinds of weird problems, for example missing terms, duplicate terms, 
etc. 
> > 
> > I don't like the idea of creating a new queryparser for each query, so I 
am looking for alternatives. Any ideas?
> 
> Using a non-threadsafe object in a threaded environment is fairly
> standard in Java, just wrap it in a synchronized block. 
> 
> If you don't want all threads waiting on one query parser, create a pool
> of them. 

Or use one parser per thread.

Regards,
Paul Elschot


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: QueryParser not thread-safe

Posted by Luke Francl <lu...@stellent.com>.
On Tue, 2005-08-23 at 12:01, Miles Barr wrote:
> Using a non-threadsafe object in a threaded environment is fairly
> standard in Java, just wrap it in a synchronized block. 
> 
> If you don't want all threads waiting on one query parser, create a pool
> of them. 

Based on doing the simplest possible thing, I would recommend creating a
new parser for every thread using QueryParser.parse( String, String,
Analyzer) until/unless you determine this is a performance bottleneck.

Regards,
Luke Francl


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: QueryParser not thread-safe

Posted by Miles Barr <mi...@runtime-collective.com>.
On Tue, 2005-08-23 at 13:47 -0300, jhandl@fibertel.com.ar wrote:
> Hi! I've been having problems with lucene's QueryParser, apparently it is not thread-safe. 
> 
> That means I can't parse queries in threads where the queryparser object is created once and reused for each query. If I do, the resulting queries may have all kinds of weird problems, for example missing terms, duplicate terms, etc. 
> 
> I don't like the idea of creating a new queryparser for each query, so I am looking for alternatives. Any ideas?

Using a non-threadsafe object in a threaded environment is fairly
standard in Java, just wrap it in a synchronized block. 

If you don't want all threads waiting on one query parser, create a pool
of them. 


-- 
Miles Barr <mi...@runtime-collective.com>
Runtime Collective Ltd.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org