the question is like this: when one user is using IndexWirter.addDocument(doc), and another user has already finished adding part and have closed IndexWirter, then, the first user embraces the error "ERROR: this IndexWriter is closed", cause both of them creat the IndexWriter based on RAM by the same sever.
I followed the error to the lucene source, there is ensureOpen(); in IndexWirter.addDocument( ), and the error is there, protected synchronized final void ensureOpen(boolean includePendingClose) throws AlreadyClosedException { if (!isOpen(includePendingClose)) { throw new AlreadyClosedException("this IndexWriter is closed"); } } how to avoid these kind of error? could lucene check this kind of sitation by itself? 2010/8/17 xiaoyan Zheng <hillyzh...@gmail.com> > > about RAMDirectory based B/S plantform problem > > hello, I just start to use lucene and become confused about RAMDirectory > based lucene index establishment, the problem is one user use this RAM to > establish index is ok, but, when it comes to multi user, the results is not > correct. when i use synchronized{ writer.writeIndex (...)}, all go alright. > but users have to wait. i mean, is that RAM can only be used in single > thread, esp. writing the index? how to solve it in a B/S plantform? > > ============================ > the detailed test code is like these, very simple, just use jsp: > > > RAMDirectory idx=new RAMDirectory(); > > LuceneIndexWriterImpl writer=null; > writer=LuceneIndexWriterImpl.getInstance(); > > //RAM-based lucene index establishment > > synchronized(wirter){ > //if no synchronized the result is not correct > writer.writeIndex(idx); > > } > > LuceneIndexReaderImpl luceneReader=new LuceneIndexReaderImpl(idx); > .... > .... > > out.println("****"); > for(Integer id :documents.keySet()) > out.println(id); > out.println("****"); > > =========================== > result: > if only one user: out put is correct 7,3 > > but two users(if no synchronized): out put may be 0,0 and 4, 0 or other > unexpected result. > > > Regards > Hilly >