lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Rhoden <>
Subject Multiple threads under tomcat
Date Wed, 11 Nov 2009 00:23:54 GMT
Apologies if this info is already somewhere, but google cant find it  
(: I am assuming the following code is completely thread safe:

// Called from a servlet when a user action results in the index  
needing to be updated
public static void rebuildIndex() {
	FSDirectory dir = new NIOFSDirectory(new  
File(Configuration.getAttachmentFolder()), null);
	IndexWriter w = new IndexWriter(dir, analyzer,  
	.... build index ...

The following code is called from the search servlet:

// Called by the search servlet
public void search() {
	FSDirectory dir = new NIOFSDirectory(new  
File(Configuration.getAttachmentFolder()), null);
	IndexReader indexReader =,true);
	IndexSearcher searcher = new IndexSearcher(indexReader);
	.... do the search ...

I am trying to work out the best/correct way to improve upon this:

1) Should the "FSDirectory dir" object be shared as some sort of  
static variable?
2) Should the "IndexSearcher searcher" or the "IndexReader  
indexReader" objects be stored as a static variable, and then simply  
replaced when the index is rebuilt?


Information Technology Services,
The University of Melbourne

Phone: +61 3 8344 2884
Mobile: +61 4 1095 7575

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message