org.exist.storage.journal
Class FileSyncThread

java.lang.Object
  extended byjava.lang.Thread
      extended byorg.exist.storage.journal.FileSyncThread
All Implemented Interfaces:
java.lang.Runnable

public class FileSyncThread
extends java.lang.Thread

Sync the current journal file by calling FileChannel.force(boolean). This operation is quite expensive, so we delegate it to a background thread. The main logging thread can continue to write into the log buffer and does not need to wait until the force operation returns. However, we have to make sure that only one sync operation is running at a time. So if the main logging thread triggers another sync while one is already in progress, it has to wait until the sync operation has finished.

Author:
wolf

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
FileSyncThread(java.lang.Object latch)
          Create a new FileSyncThread, using the specified latch to synchronize on.
 
Method Summary
 void closeChannel()
          Close the underlying channel.
 void run()
          Wait for a sync event or shutdown.
 void setChannel(java.nio.channels.FileChannel channel)
          Set the channel opened on the current journal file.
 void shutdown()
          Shutdown the sync thread.
 void triggerSync()
          Trigger a sync on the journal.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FileSyncThread

public FileSyncThread(java.lang.Object latch)
Create a new FileSyncThread, using the specified latch to synchronize on.

Parameters:
latch -
Method Detail

setChannel

public void setChannel(java.nio.channels.FileChannel channel)
Set the channel opened on the current journal file. Called by Journal when it switches to a new file.

Parameters:
channel -

triggerSync

public void triggerSync()
Trigger a sync on the journal. If a sync is already in progress, the method will just wait until the sync has completed.


shutdown

public void shutdown()
Shutdown the sync thread.


closeChannel

public void closeChannel()
Close the underlying channel.


run

public void run()
Wait for a sync event or shutdown.



Copyright (C) Wolfgang Meier. All rights reserved.