jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1169813 - in /jackrabbit/branches/JCR-2936: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/
Date Mon, 12 Sep 2011 16:11:15 GMT
Author: jukka
Date: Mon Sep 12 16:11:15 2011
New Revision: 1169813

URL: http://svn.apache.org/viewvc?rev=1169813&view=rev
Log:
Merge recent changes from trunk to the JCR-2936 branch

Added:
    jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/JackrabbitThreadPool.java
      - copied unchanged from r1169810, jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/JackrabbitThreadPool.java
Modified:
    jackrabbit/branches/JCR-2936/   (props changed)
    jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
    jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
    jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
    jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
    jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java
    jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java
    jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java

Propchange: jackrabbit/branches/JCR-2936/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Sep 12 16:11:15 2011
@@ -1,2 +1,2 @@
 /jackrabbit/sandbox/JCR-2415-lucene-3.0:1060860-1064038
-/jackrabbit/trunk:1160161-1169494
+/jackrabbit/trunk:1160161-1169810

Modified: jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java?rev=1169813&r1=1169812&r2=1169813&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
(original)
+++ jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
Mon Sep 12 16:11:15 2011
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.core;
 
+import java.util.concurrent.ScheduledExecutorService;
+
 import org.apache.jackrabbit.core.cluster.ClusterNode;
 import org.apache.jackrabbit.core.data.DataStore;
 import org.apache.jackrabbit.core.fs.FileSystem;
@@ -27,7 +29,6 @@ import org.apache.jackrabbit.core.securi
 import org.apache.jackrabbit.core.state.ItemStateCacheFactory;
 import org.apache.jackrabbit.core.stats.StatManager;
 import org.apache.jackrabbit.core.version.InternalVersionManagerImpl;
-import org.apache.jackrabbit.util.Timer;
 
 /**
  * Internal component context of a Jackrabbit content repository.
@@ -101,9 +102,10 @@ public class RepositoryContext {
     private NodeIdFactory nodeIdFactory;
 
     /**
-     * Repository-wide timer instance.
+     * Thread pool of this repository.
      */
-    private final Timer timer = new Timer(false);
+    private final ScheduledExecutorService executor =
+            new JackrabbitThreadPool();
 
     /**
      * The Statistics manager, handles statistics and jmx support
@@ -130,12 +132,12 @@ public class RepositoryContext {
     }
 
     /**
-     * Returns the repository-wide timer instance.
+     * Returns the thread pool of this repository.
      *
-     * @return repository timer
+     * @return repository thread pool
      */
-    public Timer getTimer() {
-        return timer;
+    public ScheduledExecutorService getExecutor() {
+        return executor;
     }
 
     /**

Modified: jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?rev=1169813&r1=1169812&r2=1169813&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
(original)
+++ jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
Mon Sep 12 16:11:15 2011
@@ -32,11 +32,7 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledThreadPoolExecutor;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.jcr.AccessDeniedException;
 import javax.jcr.Credentials;
@@ -243,11 +239,6 @@ public class RepositoryImpl extends Abst
     private WorkspaceEventChannel createWorkspaceEventChannel;
 
     /**
-     * Scheduled executor service.
-     */
-    protected final ScheduledExecutorService executor;
-
-    /**
      * Protected constructor.
      *
      * @param repConfig the repository configuration.
@@ -256,32 +247,6 @@ public class RepositoryImpl extends Abst
      *                             or another error occurs.
      */
     protected RepositoryImpl(RepositoryConfig repConfig) throws RepositoryException {
-        // we should use the jackrabbit classloader for all background threads
-        // from the pool
-        final ClassLoader poolClassLoader = this.getClass().getClassLoader();
-        ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(
-                Runtime.getRuntime().availableProcessors() * 2,
-                new ThreadFactory() {
-
-                    final AtomicInteger threadNumber = new AtomicInteger(1);
-
-                    /**
-                     * @see java.util.concurrent.ThreadFactory#newThread(java.lang.Runnable)
-                     */
-                    public Thread newThread(Runnable r) {
-                        final Thread t = new Thread(null, r,
-                                              "jackrabbit-pool-" + threadNumber.getAndIncrement(),
-                                              0);
-                        t.setDaemon(true);
-                        if (t.getPriority() != Thread.NORM_PRIORITY)
-                            t.setPriority(Thread.NORM_PRIORITY);
-                        t.setContextClassLoader(poolClassLoader);
-                        return t;
-                    }
-                },
-                new ThreadPoolExecutor.CallerRunsPolicy());
-        this.executor = executor;
-
         // Acquire a lock on the repository home
         repLock = repConfig.getRepositoryLockMechanism();
         repLock.init(repConfig.getHomeDir());
@@ -657,8 +622,7 @@ public class RepositoryImpl extends Abst
                         repConfig,
                         getWorkspaceInfo(wspName).itemStateMgr,
                         context.getInternalVersionManager().getPersistenceManager(),
-                        SYSTEM_ROOT_NODE_ID,
-                        null, null, executor);
+                        SYSTEM_ROOT_NODE_ID, null, null);
 
                 SystemSession defSysSession = getSystemSession(wspName);
                 ObservationManager obsMgr = defSysSession.getWorkspace().getObservationManager();
@@ -1182,6 +1146,7 @@ public class RepositoryImpl extends Abst
         notifyAll();
 
         // Shut down the executor service
+        ScheduledExecutorService executor = context.getExecutor();
         executor.shutdown();
         try {
             // Wait for all remaining background threads to terminate
@@ -1204,8 +1169,6 @@ public class RepositoryImpl extends Abst
             }
         }
 
-        context.getTimer().cancel();
-
         statManager.stop();
 
         log.info("Repository has been shutdown");
@@ -1914,7 +1877,7 @@ public class RepositoryImpl extends Abst
                             itemStateMgr, persistMgr,
                             context.getRootNodeId(),
                             getSystemSearchManager(getName()),
-                            SYSTEM_ROOT_NODE_ID, executor);
+                            SYSTEM_ROOT_NODE_ID);
                 }
                 return searchMgr;
             }
@@ -1954,7 +1917,8 @@ public class RepositoryImpl extends Abst
          * @return the lock manager
          */
         protected LockManagerImpl createLockManager() throws RepositoryException {
-            return new LockManagerImpl(getSystemSession(), fs, executor);
+            return new LockManagerImpl(
+                    getSystemSession(), fs, context.getExecutor());
         }
 
         /**

Modified: jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java?rev=1169813&r1=1169812&r2=1169813&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
(original)
+++ jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
Mon Sep 12 16:11:15 2011
@@ -130,12 +130,11 @@ public class SearchManager implements Sy
     public SearchManager(
             RepositoryContext repositoryContext,
             QueryHandlerFactory qhf,
-                         SharedItemStateManager itemMgr,
-                         PersistenceManager pm,
-                         NodeId rootNodeId,
-                         SearchManager parentMgr,
-                         NodeId excludedNodeId,
-                         Executor executor) throws RepositoryException {
+            SharedItemStateManager itemMgr,
+            PersistenceManager pm,
+            NodeId rootNodeId,
+            SearchManager parentMgr,
+            NodeId excludedNodeId) throws RepositoryException {
         this.nsReg = repositoryContext.getNamespaceRegistry();
         this.itemMgr = itemMgr;
         this.parentHandler = (parentMgr != null) ? parentMgr.handler : null;
@@ -174,7 +173,7 @@ public class SearchManager implements Sy
         this.handler = qhf.getQueryHandler(new QueryHandlerContext(
                 repositoryContext,
                 itemMgr, pm, rootNodeId,
-                parentHandler, excludedNodeId, executor));
+                parentHandler, excludedNodeId));
     }
 
     /**

Modified: jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java?rev=1169813&r1=1169812&r2=1169813&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
(original)
+++ jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
Mon Sep 12 16:11:15 2011
@@ -16,16 +16,15 @@
  */
 package org.apache.jackrabbit.core;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.jackrabbit.util.Timer;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.transaction.xa.XAException;
 import javax.transaction.xa.Xid;
 
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Represents the transaction on behalf of the component that wants to
@@ -35,7 +34,7 @@ import java.util.Map;
  * of the resources' {@link InternalXAResource#prepare} method, are eventually
  * unlocked.
  */
-public class TransactionContext extends Timer.Task {
+public class TransactionContext {
 
     /**
      * Logger instance.
@@ -55,26 +54,11 @@ public class TransactionContext extends 
     private static final ThreadLocal<Xid> CURRENT_XID = new ThreadLocal<Xid>();
 
     /**
-     * Timer for all transaction contexts.
-     */
-    private final Timer timer;
-
-    /**
      * Transactional resources.
      */
     private final InternalXAResource[] resources;
 
     /**
-     * Timeout, in seconds.
-     */
-    private final int timeout;
-
-    /**
-     * Indicates if this {@link TransactionContext} has timed out internally
-     */
-    private boolean timedOut = false;
-
-    /**
     * The Xid
     */
    private final Xid xid;
@@ -96,17 +80,13 @@ public class TransactionContext extends 
 
     /**
      * Create a new instance of this class.
+     *
      * @param xid associated xid
      * @param resources transactional resources
-     * @param timeout timeout, in seconds
      */
-    public TransactionContext(
-            Xid xid, InternalXAResource[] resources,
-            int timeout, Timer timer) {
+    public TransactionContext(Xid xid, InternalXAResource[] resources) {
         this.xid = xid;
         this.resources = resources;
-        this.timeout = timeout;
-        this.timer = timer;
     }
 
     /**
@@ -149,11 +129,10 @@ public class TransactionContext extends 
      * all resources. If some resource reports an error on prepare,
      * automatically rollback changes on all other resources. Throw exception
      * at the end if errors were found.
-     * @param onePhaseOptimized if true this prepare comes from a onePhase optimized Transaction.
-     * 			Internal Timeout-Task will be started.
+     *
      * @throws XAException if an error occurs
      */
-    public synchronized void prepare(boolean onePhaseOptimized) throws XAException {
+    public synchronized void prepare() throws XAException {
         bindCurrentXid();
         status = STATUS_PREPARING;
         beforeOperation();
@@ -182,11 +161,6 @@ public class TransactionContext extends 
             e.initCause(txe);
             throw e;
         }
-
-        if (onePhaseOptimized) {
-            // start rollback task in case the commit is never issued
-            timer.schedule(this, timeout * 1000, Integer.MAX_VALUE);
-        }
     }
 
     /**
@@ -194,17 +168,14 @@ public class TransactionContext extends 
      * all resources. If some resource reports an error on commit,
      * automatically rollback changes on all other resources. Throw
      * exception at the end if some commit failed.
-     * @param true if the commit comes from a onePhase optimized Transaction.
+     *
      * @throws XAException if an error occurs
      */
-    public synchronized void commit(boolean onePhase) throws XAException {
+    public synchronized void commit() throws XAException {
         if (status == STATUS_ROLLED_BACK) {
-            if (onePhase && timedOut) {
-                throw new XAException(XAException.XA_RBTIMEOUT);
-            } else {
-                throw new XAException(XAException.XA_HEURRB);
-            }
+            throw new XAException(XAException.XA_HEURRB);
         }
+
         boolean heuristicCommit = false;
         bindCurrentXid();
         status = STATUS_COMMITTING;
@@ -231,10 +202,6 @@ public class TransactionContext extends 
         afterOperation();
         status = STATUS_COMMITTED;
 
-        if (onePhase) {
-            // cancel the rollback task only in onePhase Transactions
-            cancel();
-        }
         cleanCurrentXid();
 
         if (txe != null) {
@@ -275,8 +242,6 @@ public class TransactionContext extends 
         afterOperation();
         status = STATUS_ROLLED_BACK;
 
-        // cancel the rollback task
-        cancel();
         cleanCurrentXid();
 
         if (errors != 0) {
@@ -285,26 +250,6 @@ public class TransactionContext extends 
     }
 
     /**
-     * Rolls back the transaction if still prepared and marks the transaction
-     * rolled back.
-     */
-    public void run() {
-        synchronized (this) {
-            if (status == STATUS_PREPARED) {
-                try {
-                    rollback();
-                } catch (XAException e) {
-                    /* ignore */
-                }
-                timedOut = true;
-                log.warn("Transaction rolled back because timeout expired.");
-            }
-            // cancel the rollback task
-            cancel();
-        }
-    }
-
-    /**
      * Invoke all of the registered resources' {@link InternalXAResource#beforeOperation}
      * methods.
      */

Modified: jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java?rev=1169813&r1=1169812&r2=1169813&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java
(original)
+++ jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java
Mon Sep 12 16:11:15 2011
@@ -251,9 +251,7 @@ public class XASessionImpl extends Sessi
      * @return transaction context
      */
     private TransactionContext createTransaction(Xid xid) {
-        TransactionContext tx = new TransactionContext(
-                xid, txResources,
-                getTransactionTimeout(), repositoryContext.getTimer());
+        TransactionContext tx = new TransactionContext(xid, txResources);
         txGlobal.put(xid, tx);
         return tx;
     }
@@ -309,7 +307,7 @@ public class XASessionImpl extends Sessi
         if (tx == null) {
             throw new XAException(XAException.XAER_NOTA);
         }
-        tx.prepare(false);
+        tx.prepare();
         return XA_OK;
     }
 
@@ -322,9 +320,9 @@ public class XASessionImpl extends Sessi
             throw new XAException(XAException.XAER_NOTA);
         }
         if (onePhase) {
-            tx.prepare(onePhase);
+            tx.prepare();
         }
-        tx.commit(onePhase);
+        tx.commit();
 
         txGlobal.remove(xid);
     }

Modified: jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java?rev=1169813&r1=1169812&r2=1169813&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java
(original)
+++ jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java
Mon Sep 12 16:11:15 2011
@@ -16,7 +16,7 @@
  */
 package org.apache.jackrabbit.core.query;
 
-import java.util.concurrent.Executor;
+import java.util.concurrent.ScheduledExecutorService;
 
 import org.apache.jackrabbit.core.CachingHierarchyManager;
 import org.apache.jackrabbit.core.HierarchyManager;
@@ -27,7 +27,6 @@ import org.apache.jackrabbit.core.nodety
 import org.apache.jackrabbit.core.persistence.PersistenceManager;
 import org.apache.jackrabbit.core.state.ItemStateManager;
 import org.apache.jackrabbit.core.state.SharedItemStateManager;
-import org.apache.jackrabbit.util.Timer;
 
 /**
  * Acts as an argument for the {@link QueryHandler} to keep the interface
@@ -77,11 +76,6 @@ public class QueryHandlerContext {
     private final NodeId excludedNodeId;
 
     /**
-     * Background task executor.
-     */
-    private final Executor executor;
-
-    /**
      * Creates a new context instance.
      *
      * @param stateMgr         provides persistent item states.
@@ -92,7 +86,6 @@ public class QueryHandlerContext {
      * @param excludedNodeId   id of the node that should be excluded from
      *                         indexing. Any descendant of that node is also
      *                         excluded from indexing.
-     * @param executor         background task executor
      */
     public QueryHandlerContext(
             RepositoryContext repositoryContext,
@@ -100,8 +93,7 @@ public class QueryHandlerContext {
             PersistenceManager pm,
             NodeId rootId,
             QueryHandler parentHandler,
-            NodeId excludedNodeId,
-            Executor executor) {
+            NodeId excludedNodeId) {
         this.repositoryContext = repositoryContext;
         this.stateMgr = stateMgr;
         this.hmgr = new CachingHierarchyManager(rootId, stateMgr);
@@ -112,7 +104,6 @@ public class QueryHandlerContext {
         propRegistry = new PropertyTypeRegistry(ntRegistry);
         this.parentHandler = parentHandler;
         this.excludedNodeId = excludedNodeId;
-        this.executor =  executor;
         ntRegistry.addListener(propRegistry);
     }
 
@@ -206,17 +197,8 @@ public class QueryHandlerContext {
      *
      * @return background task executor
      */
-    public Executor getExecutor() {
-        return executor;
-    }
-
-    /**
-     * Returns the repository timer.
-     *
-     * @return repository timer
-     */
-    public Timer getTimer() {
-        return repositoryContext.getTimer();
+    public ScheduledExecutorService getExecutor() {
+        return repositoryContext.getExecutor();
     }
 
 }

Modified: jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java?rev=1169813&r1=1169812&r2=1169813&view=diff
==============================================================================
--- jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
(original)
+++ jackrabbit/branches/JCR-2936/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
Mon Sep 12 16:11:15 2011
@@ -29,6 +29,9 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
 
 import javax.jcr.RepositoryException;
 
@@ -44,7 +47,6 @@ import org.apache.jackrabbit.spi.PathFac
 import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
 import org.apache.jackrabbit.spi.commons.conversion.PathResolver;
 import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
-import org.apache.jackrabbit.util.Timer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
@@ -175,7 +177,7 @@ public class MultiIndex {
     /**
      * The time this index was last flushed or a transaction was committed.
      */
-    private long lastFlushTime;
+    private long lastFlushTime = 0;
 
     /**
      * The <code>IndexMerger</code> for this <code>MultiIndex</code>.
@@ -186,7 +188,7 @@ public class MultiIndex {
      * Task that is periodically called by the repository timer for checking
      * if index should be flushed.
      */
-    private final Timer.Task flushTask;
+    private ScheduledFuture<?> flushTask = null;
 
     /**
      * The RedoLog of this <code>MultiIndex</code>.
@@ -329,15 +331,6 @@ public class MultiIndex {
             flush();
         }
 
-        flushTask = new Timer.Task() {
-            public void run() {
-                // check if there are any indexing jobs finished
-                checkIndexingQueue(false);
-                // check if volatile index should be flushed
-                checkFlush();
-            }
-        };
-
         if (indexNames.size() > 0) {
             scheduleFlushTask();
         }
@@ -798,7 +791,7 @@ public class MultiIndex {
 
         synchronized (this) {
             // stop timer
-            flushTask.cancel();
+            unscheduleFlushTask();
 
             // commit / close indexes
             try {
@@ -1074,9 +1067,29 @@ public class MultiIndex {
         indexHistory.pruneOutdated();
     }
 
+    /**
+     * Schedules a background task for flushing the index once per second.
+     */
     private void scheduleFlushTask() {
-        lastFlushTime = System.currentTimeMillis();
-        handler.getContext().getTimer().schedule(flushTask, 0, 1000);
+        ScheduledExecutorService executor = handler.getContext().getExecutor();
+        flushTask = executor.scheduleWithFixedDelay(new Runnable() {
+            public void run() {
+                // check if there are any indexing jobs finished
+                checkIndexingQueue(false);
+                // check if volatile index should be flushed
+                checkFlush();
+            }
+        }, 1, 1, TimeUnit.SECONDS);
+    }
+
+    /**
+     * Cancels the scheduled background index flush task.
+     */
+    private void unscheduleFlushTask() {
+        if (flushTask != null) {
+            flushTask.cancel(false);
+            flushTask = null;
+        }
     }
 
     /**



Mime
View raw message