From: <wol...@us...> - 2013-06-29 16:56:57
|
Revision: 18626 http://sourceforge.net/p/exist/code/18626 Author: wolfgang_m Date: 2013-06-29 16:56:53 +0000 (Sat, 29 Jun 2013) Log Message: ----------- [bugfix] Applied patch: #820 FileSyncThread may access null endOfLog Modified Paths: -------------- trunk/eXist/src/org/exist/storage/journal/FileSyncThread.java Modified: trunk/eXist/src/org/exist/storage/journal/FileSyncThread.java =================================================================== --- trunk/eXist/src/org/exist/storage/journal/FileSyncThread.java 2013-06-29 16:52:39 UTC (rev 18625) +++ trunk/eXist/src/org/exist/storage/journal/FileSyncThread.java 2013-06-29 16:56:53 UTC (rev 18626) @@ -39,14 +39,16 @@ */ public class FileSyncThread extends Thread { + // guarded by latch private FileChannel endOfLog; - + private Object latch; + + // guarded by this private boolean syncTriggered = false; - private boolean shutdown = false; + // used as termination flag, volatile semantics are sufficient + private volatile boolean shutdown = false; - private Object latch; - /** * Create a new FileSyncThread, using the specified latch * to synchronize on. @@ -66,7 +68,9 @@ * @param channel */ public void setChannel(FileChannel channel) { - endOfLog = channel; + synchronized (latch) { + endOfLog = channel; + } } /** @@ -82,7 +86,7 @@ /** * Shutdown the sync thread. */ - public synchronized void shutdown() { + public void shutdown() { shutdown = true; interrupt(); } @@ -92,11 +96,13 @@ */ public void closeChannel() { synchronized (latch) { - try { - endOfLog.close(); - } catch (final IOException e) { - //Nothing to do - } + if (endOfLog != null) { + try { + endOfLog.close(); + } catch (final IOException e) { + // may occur during shutdown + } + } } } @@ -124,11 +130,14 @@ private void sync() { synchronized (latch) { - try { - endOfLog.force(false); - } catch (final IOException e) { - // may occur during shutdown - } + //endOfLog may be null if setChannel wasn't called for some reason. + if (endOfLog != null) { + try { + endOfLog.force(false); + } catch (final IOException e) { + // may occur during shutdown + } + } syncTriggered = false; } } |