kelvint     02/05/25 03:19:22

  Modified:    contributions/fulcrum LuceneSearchService.java
  Log:
  Method of acquiring and releasing index lock could have resulted in a deadlock 
(thanks to Otis for pointing it out).
  Made the acquire and release lock methods synchronized and centralized the point of 
access of the lock.
  
  Revision  Changes    Path
  1.2       +14 -7     
jakarta-lucene-sandbox/contributions/fulcrum/LuceneSearchService.java
  
  Index: LuceneSearchService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-lucene-sandbox/contributions/fulcrum/LuceneSearchService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LuceneSearchService.java  11 May 2002 00:46:59 -0000      1.1
  +++ LuceneSearchService.java  25 May 2002 10:19:22 -0000      1.2
  @@ -116,7 +116,7 @@
           try
           {
               acquireIndexLock();
  -            new IndexerThread(new SearchIndexer());
  +            new IndexerThread(new SearchIndexer(), this);
           }
           catch (IOException ioe)
           {
  @@ -130,7 +130,7 @@
   
       public boolean isIndexing()
       {
  -        return IndexerThread.isIndexing || indexLocked;
  +        return indexLocked;
       }
   
       public Analyzer getAnalyzer()
  @@ -142,30 +142,37 @@
           return analyzer;
       }
   
  -    private void acquireIndexLock() throws InterruptedException
  +    protected synchronized void acquireIndexLock() throws InterruptedException
       {
           while (isIndexing())
           {
               wait(500);
           }
  +        indexLocked = true;
  +    }
  +
  +    protected synchronized void releaseIndexLock()
  +    {
  +        indexLocked = false;
       }
   }
   
   class IndexerThread extends Thread
   {
  -    protected static boolean isIndexing = false;
       private static Category cat = Category.getInstance(IndexerThread.class);
   
       private SearchIndexer indexer;
  +    private LuceneSearchService service;
   
       public IndexerThread()
       {
           super();
       }
   
  -    public IndexerThread(SearchIndexer indexer)
  +    public IndexerThread(SearchIndexer indexer, LuceneSearchService service)
  +        throws InterruptedException
       {
  -        isIndexing = true;
  +        service.acquireIndexLock();
           this.indexer = indexer;
           start();
       }
  @@ -182,7 +189,7 @@
           }
           finally
           {
  -            isIndexing = false;
  +            service.releaseIndexLock();
           }
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to