Index: src/main/java/org/apache/jackrabbit/core/journal/AbstractJournal.java =================================================================== --- src/main/java/org/apache/jackrabbit/core/journal/AbstractJournal.java (revision 1382792) +++ src/main/java/org/apache/jackrabbit/core/journal/AbstractJournal.java (working copy) @@ -181,16 +181,30 @@ * {@inheritDoc} */ public void sync() throws JournalException { - if (internalVersionManager != null) { - VersioningLock.ReadLock lock = - internalVersionManager.acquireReadLock(); - try { + for (;;) { + if (internalVersionManager != null) { + VersioningLock.ReadLock lock = + internalVersionManager.acquireReadLock(); + try { + internalSync(); + } finally { + lock.release(); + } + } else { internalSync(); - } finally { - lock.release(); } - } else { - internalSync(); + if (syncAgainOnNewRecords()) { + // sync again if there are more records available + RecordIterator it = getRecords(getMinimalRevision()); + try { + if (it.hasNext()) { + continue; + } + } finally { + it.close(); + } + } + break; } } @@ -215,46 +229,37 @@ * @throws JournalException if an error occurs */ protected void doSync(long startRevision) throws JournalException { - for (;;) { - RecordIterator iterator = getRecords(startRevision); - long stopRevision = Long.MIN_VALUE; - - try { - while (iterator.hasNext()) { - Record record = iterator.nextRecord(); - if (record.getJournalId().equals(id)) { - log.info("Record with revision '" + record.getRevision() - + "' created by this journal, skipped."); - } else { - RecordConsumer consumer = getConsumer(record.getProducerId()); - if (consumer != null) { - try { - consumer.consume(record); - } catch (IllegalStateException e) { - log.error("Could not synchronize to revision: " + record.getRevision() + " due illegal state of RecordConsumer."); - return; - } + RecordIterator iterator = getRecords(startRevision); + long stopRevision = Long.MIN_VALUE; + + try { + while (iterator.hasNext()) { + Record record = iterator.nextRecord(); + if (record.getJournalId().equals(id)) { + log.info("Record with revision '" + record.getRevision() + + "' created by this journal, skipped."); + } else { + RecordConsumer consumer = getConsumer(record.getProducerId()); + if (consumer != null) { + try { + consumer.consume(record); + } catch (IllegalStateException e) { + log.error("Could not synchronize to revision: " + record.getRevision() + " due illegal state of RecordConsumer."); + return; } } - stopRevision = record.getRevision(); } - } finally { - iterator.close(); + stopRevision = record.getRevision(); } - - if (stopRevision > 0) { - for (RecordConsumer consumer : consumers.values()) { - consumer.setRevision(stopRevision); - } - log.info("Synchronized to revision: " + stopRevision); + } finally { + iterator.close(); + } - if (syncAgainOnNewRecords()) { - // changes detected, sync again - startRevision = stopRevision; - continue; - } + if (stopRevision > 0) { + for (RecordConsumer consumer : consumers.values()) { + consumer.setRevision(stopRevision); } - break; + log.info("Synchronized to revision: " + stopRevision); } }