FAQ
Hello

My code looks like this:

Directory dir = null;
try {
dir = FSDirectory.getDirectory("/path/to/dictionary");
SpellChecker spell = new SpellChecker(dir); // exception thrown here
// ...
dir.close();
} catch (IOException ex) {
log error
} finally {
if (dir!=null) {
try {
dir.close();
} catch (IOException ex) {
log error
}
}
}


This code works, but in a highly concurrent situation
AlreadyClosedException is being thrown when I try to instantiate the
SpellChecker:
org.apache.lucene.store.AlreadyClosedException: this Directory is closed
at org.apache.lucene.store.Directory.ensureOpen(Directory.java:220)
at org.apache.lucene.store.FSDirectory.openInput(FSDirectory.java:481)
at org.apache.lucene.index.SegmentInfos.read(SegmentInfos.java:214)
at
org.apache.lucene.index.DirectoryIndexReader$1.doBody(DirectoryIndexReader.java:95)
at
org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:653)
at
org.apache.lucene.index.DirectoryIndexReader.open(DirectoryIndexReader.java:115)
at org.apache.lucene.index.IndexReader.open(IndexReader.java:316)
at org.apache.lucene.index.IndexReader.open(IndexReader.java:227)
at org.apache.lucene.search.IndexSearcher.(SpellChecker.java:116)
at
org.apache.lucene.search.spell.SpellChecker.(SpellChecker.java:95)


I use lucene-core-2.4.1.jar and lucene-spellchecker-2.4.1.jar and I can
reproduce the error in both windows and linux.
Any ideas on what is wrong?

thanks
Ioannis Cherouvim

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

Search Discussions

  • Chris Hostetter at Apr 9, 2009 at 11:16 pm
    : My code looks like this:
    :
    : Directory dir = null;
    : try {
    : dir = FSDirectory.getDirectory("/path/to/dictionary");
    : SpellChecker spell = new SpellChecker(dir); // exception thrown here
    : // ...
    : dir.close();

    : This code works, but in a highly concurrent situation AlreadyClosedException
    : is being thrown when I try to instantiate the SpellChecker:
    : org.apache.lucene.store.AlreadyClosedException: this Directory is closed

    if an error only happens under high concurrent load, it suggests that
    perhaps you have multiple threads attempting to close the directory. you
    haven't clarified whether "dir" is a local variable inside a method, or an
    instnace variable in an object which is getting reused by multiple
    threads -- so it's hard to guess.

    : I use lucene-core-2.4.1.jar and lucene-spellchecker-2.4.1.jar and I can
    : reproduce the error in both windows and linux.

    if you have a fully exeuctable test case (instead of just an incomplete
    partial snippet) that you can share, people may be able to spot the
    problem, or at the very least run the test themselves to reproduce.


    -Hoss


    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • John Cherouvim at Apr 10, 2009 at 8:54 am
    dir is a local variable inside a method, so it's not getting reused.
    Should I synchronise the whole method? I think that would slow things
    down in a concurrent environment.

    Thanks for your response.


    Chris Hostetter wrote:
    : My code looks like this:
    :
    : Directory dir = null;
    : try {
    : dir = FSDirectory.getDirectory("/path/to/dictionary");
    : SpellChecker spell = new SpellChecker(dir); // exception thrown here
    : // ...
    : dir.close();

    : This code works, but in a highly concurrent situation AlreadyClosedException
    : is being thrown when I try to instantiate the SpellChecker:
    : org.apache.lucene.store.AlreadyClosedException: this Directory is closed

    if an error only happens under high concurrent load, it suggests that
    perhaps you have multiple threads attempting to close the directory. you
    haven't clarified whether "dir" is a local variable inside a method, or an
    instnace variable in an object which is getting reused by multiple
    threads -- so it's hard to guess.

    : I use lucene-core-2.4.1.jar and lucene-spellchecker-2.4.1.jar and I can
    : reproduce the error in both windows and linux.

    if you have a fully exeuctable test case (instead of just an incomplete
    partial snippet) that you can share, people may be able to spot the
    problem, or at the very least run the test themselves to reproduce.


    -Hoss


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

    --
    Ioannis Cherouvim
    Software Engineer
    mail: jc@eworx.gr
    web: www.eworx.gr


    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Chris Hostetter at Apr 14, 2009 at 11:02 pm
    : dir is a local variable inside a method, so it's not getting reused.
    : Should I synchronise the whole method? I think that would slow things down in
    : a concurrent environment.

    i don't really have any new advice beyond my previous comment...

    : > if you have a fully exeuctable test case (instead of just an incomplete
    : > partial snippet) that you can share, people may be able to spot the problem,
    : > or at the very least run the test themselves to reproduce.

    ...it's hard to speculate what might be going wrong without having code
    that can reproduce it.


    -Hoss


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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-user @
categorieslucene
postedApr 2, '09 at 10:53a
activeApr 14, '09 at 11:02p
posts4
users2
websitelucene.apache.org

2 users in discussion

John Cherouvim: 2 posts Chris Hostetter: 2 posts

People

Translate

site design / logo © 2022 Grokbase