Singleton and Lucene: org.apache.lucene.store.AlreadyClosed

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Singleton and Lucene: org.apache.lucene.store.AlreadyClosed

Zender00
Hi,
I tried to implement a singleton pattern for my already working lucene object.
But there is a strange error when I tried to access the instance.

When my Singleton GetInstance() method is executed for the first time it creates a new instance of my lucene object. There are some member variables in this object like an IndexWriter and IndexReader. These objects are created in the constructor and I can access them directly in the constructor successfully.
GetInstance() now returns this lucene object and I have to execute some operations on it. But the IndexWriter seems to be closed meanwhile and I got the exception:

"org.apache.lucene.store.AlreadyClosed    Exception: this IndexWriter is
closed" when my object tries to writer some documents.

How could this happen? Isn't it possible to use lucene with a singleton-pattern?

Kind regards,
D. Penning
Reply | Threaded
Open this post in threaded view
|

Re: Singleton and Lucene: org.apache.lucene.store.AlreadyClosed

Zender00
I extend my original post:
How is it possible to use lucene in 2 diffent classes / objects, if I dont want to use static methods/variables?
(one object read/writer, the other is read only)

Kind regards,
D. Penning
Zender00 wrote
Hi,
I tried to implement a singleton pattern for my already working lucene object.
But there is a strange error when I tried to access the instance.

When my Singleton GetInstance() method is executed for the first time it creates a new instance of my lucene object. There are some member variables in this object like an IndexWriter and IndexReader. These objects are created in the constructor and I can access them directly in the constructor successfully.
GetInstance() now returns this lucene object and I have to execute some operations on it. But the IndexWriter seems to be closed meanwhile and I got the exception:

"org.apache.lucene.store.AlreadyClosed    Exception: this IndexWriter is
closed" when my object tries to writer some documents.

How could this happen? Isn't it possible to use lucene with a singleton-pattern?

Kind regards,
D. Penning
Reply | Threaded
Open this post in threaded view
|

Re: Singleton and Lucene: org.apache.lucene.store.AlreadyClosed

Paul Libbrecht
We use singletons all the time,

Just be careful that are writer and a reader cannot be opened  
simultaneously on the same index. Either you write or your read (and  
delete).

paul


Le 15-déc.-08 à 12:06, Zender00 a écrit :

>
> I extend my original post:
> How is it possible to use lucene in 2 diffent classes / objects, if  
> I dont
> want to use static methods/variables?
> (one object read/writer, the other is read only)
>
> Kind regards,
> D. Penning
>
> Zender00 wrote:
>>
>> Hi,
>> I tried to implement a singleton pattern for my already working  
>> lucene
>> object.
>> But there is a strange error when I tried to access the instance.
>>
>> When my Singleton GetInstance() method is executed for the first  
>> time it
>> creates a new instance of my lucene object. There are some member
>> variables in this object like an IndexWriter and IndexReader. These
>> objects are created in the constructor and I can access them  
>> directly in
>> the constructor successfully.
>> GetInstance() now returns this lucene object and I have to execute  
>> some
>> operations on it. But the IndexWriter seems to be closed meanwhile  
>> and I
>> got the exception:
>>
>> "org.apache.lucene.store.AlreadyClosed    Exception: this  
>> IndexWriter is
>> closed" when my object tries to writer some documents.
>>
>> How could this happen? Isn't it possible to use lucene with a
>> singleton-pattern?
>>
>> Kind regards,
>> D. Penning
>>
>
> --
> View this message in context: http://www.nabble.com/Singleton-and-Lucene%3A-org.apache.lucene.store.AlreadyClosed-tp20983056p21011945.html
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


smime.p7s (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Singleton and Lucene: org.apache.lucene.store.AlreadyClosed

Zender00
Hi paul,

in my opinion it is possible to use a reader and writer simultanesously on the same index. In my already working lucene class, I use they are both open all the time.

But this isnt the reason for my exception. It seems that lucene cannot handle my singleton. How did you implement your singleton with lucene? Which lucene version?

Thanks for your reply,
D. Penning

polx wrote
We use singletons all the time,

Just be careful that are writer and a reader cannot be opened  
simultaneously on the same index. Either you write or your read (and  
delete).

paul


Le 15-déc.-08 à 12:06, Zender00 a écrit :

>
> I extend my original post:
> How is it possible to use lucene in 2 diffent classes / objects, if  
> I dont
> want to use static methods/variables?
> (one object read/writer, the other is read only)
>
> Kind regards,
> D. Penning
>
> Zender00 wrote:
>>
>> Hi,
>> I tried to implement a singleton pattern for my already working  
>> lucene
>> object.
>> But there is a strange error when I tried to access the instance.
>>
>> When my Singleton GetInstance() method is executed for the first  
>> time it
>> creates a new instance of my lucene object. There are some member
>> variables in this object like an IndexWriter and IndexReader. These
>> objects are created in the constructor and I can access them  
>> directly in
>> the constructor successfully.
>> GetInstance() now returns this lucene object and I have to execute  
>> some
>> operations on it. But the IndexWriter seems to be closed meanwhile  
>> and I
>> got the exception:
>>
>> "org.apache.lucene.store.AlreadyClosed    Exception: this  
>> IndexWriter is
>> closed" when my object tries to writer some documents.
>>
>> How could this happen? Isn't it possible to use lucene with a
>> singleton-pattern?
>>
>> Kind regards,
>> D. Penning
>>
>
> --
> View this message in context: http://www.nabble.com/Singleton-and-Lucene%3A-org.apache.lucene.store.AlreadyClosed-tp20983056p21011945.html
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>


 
Reply | Threaded
Open this post in threaded view
|

Re: Singleton and Lucene: org.apache.lucene.store.AlreadyClosed

Paul Libbrecht



Le 15-déc.-08 à 13:09, Zender00 a écrit :
> in my opinion it is possible to use a reader and writer  
> simultanesously on
> the same index. In my already working lucene class, I use they are  
> both open
> all the time.

mmmh...

> But this isnt the reason for my exception. It seems that lucene cannot
> handle my singleton. How did you implement your singleton with  
> lucene? Which
> lucene version?

2.3.1, source code APL and GPL at:
   http://svn.activemath.org/intergeo/Platform/SearchI2G/index/

in another project, this was used with Lucene 2.0.

paul

> polx wrote:
>>
>> We use singletons all the time,
>>
>> Just be careful that are writer and a reader cannot be opened
>> simultaneously on the same index. Either you write or your read (and
>> delete).
>>
>> paul
>>
>>
>> Le 15-déc.-08 à 12:06, Zender00 a écrit :
>>
>>>
>>> I extend my original post:
>>> How is it possible to use lucene in 2 diffent classes / objects, if
>>> I dont
>>> want to use static methods/variables?
>>> (one object read/writer, the other is read only)
>>>
>>> Kind regards,
>>> D. Penning
>>>
>>> Zender00 wrote:
>>>>
>>>> Hi,
>>>> I tried to implement a singleton pattern for my already working
>>>> lucene
>>>> object.
>>>> But there is a strange error when I tried to access the instance.
>>>>
>>>> When my Singleton GetInstance() method is executed for the first
>>>> time it
>>>> creates a new instance of my lucene object. There are some member
>>>> variables in this object like an IndexWriter and IndexReader. These
>>>> objects are created in the constructor and I can access them
>>>> directly in
>>>> the constructor successfully.
>>>> GetInstance() now returns this lucene object and I have to execute
>>>> some
>>>> operations on it. But the IndexWriter seems to be closed meanwhile
>>>> and I
>>>> got the exception:
>>>>
>>>> "org.apache.lucene.store.AlreadyClosed    Exception: this
>>>> IndexWriter is
>>>> closed" when my object tries to writer some documents.
>>>>
>>>> How could this happen? Isn't it possible to use lucene with a
>>>> singleton-pattern?
>>>>
>>>> Kind regards,
>>>> D. Penning
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Singleton-and-Lucene%3A-org.apache.lucene.store.AlreadyClosed-tp20983056p21011945.html
>>> Sent from the Lucene - Java Users mailing list archive at  
>>> Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Singleton-and-Lucene%3A-org.apache.lucene.store.AlreadyClosed-tp20983056p21012798.html
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


smime.p7s (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Singleton and Lucene: org.apache.lucene.store.AlreadyClosed

Zender00
Hi Paul,
thanks for your reply.

I compared your source code and it seems that you are using the same mechanism for the singleton like me... I am using lucene 2.4 and get the exception above explained.
I am wondering why because I only create an instance of my lucene object (which itself constructs an IndexReader/IndexWriter in its constructor) and return this instance to objects which want to execute some lucene operations. So I only applied the singleton-pattern.
I am still wondering why these pattern results in my exception. Why could it happen, that these Streams (IndexWriter/IndexReader) close itself. In my opinion it is completely legal to do so.

Any other suggestions?


polx wrote
Le 15-déc.-08 à 13:09, Zender00 a écrit :
> in my opinion it is possible to use a reader and writer  
> simultanesously on
> the same index. In my already working lucene class, I use they are  
> both open
> all the time.

mmmh...

> But this isnt the reason for my exception. It seems that lucene cannot
> handle my singleton. How did you implement your singleton with  
> lucene? Which
> lucene version?

2.3.1, source code APL and GPL at:
   http://svn.activemath.org/intergeo/Platform/SearchI2G/index/

in another project, this was used with Lucene 2.0.

paul

> polx wrote:
>>
>> We use singletons all the time,
>>
>> Just be careful that are writer and a reader cannot be opened
>> simultaneously on the same index. Either you write or your read (and
>> delete).
>>
>> paul
>>
>>
>> Le 15-déc.-08 à 12:06, Zender00 a écrit :
>>
>>>
>>> I extend my original post:
>>> How is it possible to use lucene in 2 diffent classes / objects, if
>>> I dont
>>> want to use static methods/variables?
>>> (one object read/writer, the other is read only)
>>>
>>> Kind regards,
>>> D. Penning
>>>
>>> Zender00 wrote:
>>>>
>>>> Hi,
>>>> I tried to implement a singleton pattern for my already working
>>>> lucene
>>>> object.
>>>> But there is a strange error when I tried to access the instance.
>>>>
>>>> When my Singleton GetInstance() method is executed for the first
>>>> time it
>>>> creates a new instance of my lucene object. There are some member
>>>> variables in this object like an IndexWriter and IndexReader. These
>>>> objects are created in the constructor and I can access them
>>>> directly in
>>>> the constructor successfully.
>>>> GetInstance() now returns this lucene object and I have to execute
>>>> some
>>>> operations on it. But the IndexWriter seems to be closed meanwhile
>>>> and I
>>>> got the exception:
>>>>
>>>> "org.apache.lucene.store.AlreadyClosed    Exception: this
>>>> IndexWriter is
>>>> closed" when my object tries to writer some documents.
>>>>
>>>> How could this happen? Isn't it possible to use lucene with a
>>>> singleton-pattern?
>>>>
>>>> Kind regards,
>>>> D. Penning
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Singleton-and-Lucene%3A-org.apache.lucene.store.AlreadyClosed-tp20983056p21011945.html
>>> Sent from the Lucene - Java Users mailing list archive at  
>>> Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>>
>>
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Singleton-and-Lucene%3A-org.apache.lucene.store.AlreadyClosed-tp20983056p21012798.html
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>


 
Reply | Threaded
Open this post in threaded view
|

Re: Singleton and Lucene: org.apache.lucene.store.AlreadyClosed

Jia Baozhen
some docs from Lucene 2.4.0:
   * IndexReader new = r.reopen();
   * if (new != reader) {
   *   ...     // reader was reopened
   *   reader.close();
   * }
   * reader = new;

Did you follow this instruction?

It's bad in case of concurrent access in my opinion.

Do not close the reader, and try this:
org.apache.lucene.index.IndexReader.decRef() &
org.apache.lucene.index.IndexReader.incRef()


On Tue, Dec 16, 2008 at 6:06 AM, Zender00 <[hidden email]> wrote:

>
> Hi Paul,
> thanks for your reply.
>
> I compared your source code and it seems that you are using the same
> mechanism for the singleton like me... I am using lucene 2.4 and get the
> exception above explained.
> I am wondering why because I only create an instance of my lucene object
> (which itself constructs an IndexReader/IndexWriter in its constructor) and
> return this instance to objects which want to execute some lucene
> operations. So I only applied the singleton-pattern.
> I am still wondering why these pattern results in my exception. Why could
> it
> happen, that these Streams (IndexWriter/IndexReader) close itself. In my
> opinion it is completely legal to do so.
>
> Any other suggestions?
>
>
>
> polx wrote:
> >
> >
> > Le 15-déc.-08 à 13:09, Zender00 a écrit :
> >> in my opinion it is possible to use a reader and writer
> >> simultanesously on
> >> the same index. In my already working lucene class, I use they are
> >> both open
> >> all the time.
> >
> > mmmh...
> >
> >> But this isnt the reason for my exception. It seems that lucene cannot
> >> handle my singleton. How did you implement your singleton with
> >> lucene? Which
> >> lucene version?
> >
> > 2.3.1, source code APL and GPL at:
> >    http://svn.activemath.org/intergeo/Platform/SearchI2G/index/
> >
> > in another project, this was used with Lucene 2.0.
> >
> > paul
> >
> >> polx wrote:
> >>>
> >>> We use singletons all the time,
> >>>
> >>> Just be careful that are writer and a reader cannot be opened
> >>> simultaneously on the same index. Either you write or your read (and
> >>> delete).
> >>>
> >>> paul
> >>>
> >>>
> >>> Le 15-déc.-08 à 12:06, Zender00 a écrit :
> >>>
> >>>>
> >>>> I extend my original post:
> >>>> How is it possible to use lucene in 2 diffent classes / objects, if
> >>>> I dont
> >>>> want to use static methods/variables?
> >>>> (one object read/writer, the other is read only)
> >>>>
> >>>> Kind regards,
> >>>> D. Penning
> >>>>
> >>>> Zender00 wrote:
> >>>>>
> >>>>> Hi,
> >>>>> I tried to implement a singleton pattern for my already working
> >>>>> lucene
> >>>>> object.
> >>>>> But there is a strange error when I tried to access the instance.
> >>>>>
> >>>>> When my Singleton GetInstance() method is executed for the first
> >>>>> time it
> >>>>> creates a new instance of my lucene object. There are some member
> >>>>> variables in this object like an IndexWriter and IndexReader. These
> >>>>> objects are created in the constructor and I can access them
> >>>>> directly in
> >>>>> the constructor successfully.
> >>>>> GetInstance() now returns this lucene object and I have to execute
> >>>>> some
> >>>>> operations on it. But the IndexWriter seems to be closed meanwhile
> >>>>> and I
> >>>>> got the exception:
> >>>>>
> >>>>> "org.apache.lucene.store.AlreadyClosed    Exception: this
> >>>>> IndexWriter is
> >>>>> closed" when my object tries to writer some documents.
> >>>>>
> >>>>> How could this happen? Isn't it possible to use lucene with a
> >>>>> singleton-pattern?
> >>>>>
> >>>>> Kind regards,
> >>>>> D. Penning
> >>>>>
> >>>>
> >>>> --
> >>>> View this message in context:
> >>>>
> http://www.nabble.com/Singleton-and-Lucene%3A-org.apache.lucene.store.AlreadyClosed-tp20983056p21011945.html
> >>>> Sent from the Lucene - Java Users mailing list archive at
> >>>> Nabble.com.
> >>>>
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: [hidden email]
> >>>> For additional commands, e-mail: [hidden email]
> >>>>
> >>>
> >>>
> >>>
> >>>
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/Singleton-and-Lucene%3A-org.apache.lucene.store.AlreadyClosed-tp20983056p21012798.html
> >> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [hidden email]
> >> For additional commands, e-mail: [hidden email]
> >>
> >
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Singleton-and-Lucene%3A-org.apache.lucene.store.AlreadyClosed-tp20983056p21022920.html
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
Jia Baozhen
Reply | Threaded
Open this post in threaded view
|

Re: Singleton and Lucene: org.apache.lucene.store.AlreadyClosed

Ian Lea
In reply to this post by Zender00
If the reopen suggestion doesn't fix it, I suggest that you cut down
your singleton class to the absolute minimum, wrap it in a junit test
case that demonstrates the problem and post the code here.


--
Ian.


On Mon, Dec 15, 2008 at 10:06 PM, Zender00 <[hidden email]> wrote:

>
> Hi Paul,
> thanks for your reply.
>
> I compared your source code and it seems that you are using the same
> mechanism for the singleton like me... I am using lucene 2.4 and get the
> exception above explained.
> I am wondering why because I only create an instance of my lucene object
> (which itself constructs an IndexReader/IndexWriter in its constructor) and
> return this instance to objects which want to execute some lucene
> operations. So I only applied the singleton-pattern.
> I am still wondering why these pattern results in my exception. Why could it
> happen, that these Streams (IndexWriter/IndexReader) close itself. In my
> opinion it is completely legal to do so.
>
> Any other suggestions?
>
>
>
> polx wrote:
>>
>>
>> Le 15-déc.-08 à 13:09, Zender00 a écrit :
>>> in my opinion it is possible to use a reader and writer
>>> simultanesously on
>>> the same index. In my already working lucene class, I use they are
>>> both open
>>> all the time.
>>
>> mmmh...
>>
>>> But this isnt the reason for my exception. It seems that lucene cannot
>>> handle my singleton. How did you implement your singleton with
>>> lucene? Which
>>> lucene version?
>>
>> 2.3.1, source code APL and GPL at:
>>    http://svn.activemath.org/intergeo/Platform/SearchI2G/index/
>>
>> in another project, this was used with Lucene 2.0.
>>
>> paul
>>
>>> polx wrote:
>>>>
>>>> We use singletons all the time,
>>>>
>>>> Just be careful that are writer and a reader cannot be opened
>>>> simultaneously on the same index. Either you write or your read (and
>>>> delete).
>>>>
>>>> paul
>>>>
>>>>
>>>> Le 15-déc.-08 à 12:06, Zender00 a écrit :
>>>>
>>>>>
>>>>> I extend my original post:
>>>>> How is it possible to use lucene in 2 diffent classes / objects, if
>>>>> I dont
>>>>> want to use static methods/variables?
>>>>> (one object read/writer, the other is read only)
>>>>>
>>>>> Kind regards,
>>>>> D. Penning
>>>>>
>>>>> Zender00 wrote:
>>>>>>
>>>>>> Hi,
>>>>>> I tried to implement a singleton pattern for my already working
>>>>>> lucene
>>>>>> object.
>>>>>> But there is a strange error when I tried to access the instance.
>>>>>>
>>>>>> When my Singleton GetInstance() method is executed for the first
>>>>>> time it
>>>>>> creates a new instance of my lucene object. There are some member
>>>>>> variables in this object like an IndexWriter and IndexReader. These
>>>>>> objects are created in the constructor and I can access them
>>>>>> directly in
>>>>>> the constructor successfully.
>>>>>> GetInstance() now returns this lucene object and I have to execute
>>>>>> some
>>>>>> operations on it. But the IndexWriter seems to be closed meanwhile
>>>>>> and I
>>>>>> got the exception:
>>>>>>
>>>>>> "org.apache.lucene.store.AlreadyClosed    Exception: this
>>>>>> IndexWriter is
>>>>>> closed" when my object tries to writer some documents.
>>>>>>
>>>>>> How could this happen? Isn't it possible to use lucene with a
>>>>>> singleton-pattern?
>>>>>>
>>>>>> Kind regards,
>>>>>> D. Penning
>>>>>>
>>>>>
>>>>> --
>>>>> View this message in context:
>>>>> http://www.nabble.com/Singleton-and-Lucene%3A-org.apache.lucene.store.AlreadyClosed-tp20983056p21011945.html
>>>>> Sent from the Lucene - Java Users mailing list archive at
>>>>> Nabble.com.
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [hidden email]
>>>>> For additional commands, e-mail: [hidden email]
>>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Singleton-and-Lucene%3A-org.apache.lucene.store.AlreadyClosed-tp20983056p21012798.html
>>> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Singleton-and-Lucene%3A-org.apache.lucene.store.AlreadyClosed-tp20983056p21022920.html
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]