From 4bace216b91c9f8244976305f462fd212b0e20c3 Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Tue, 21 Aug 2012 23:28:50 +0000 Subject: [PATCH] updated fix: https://issues.apache.org/jira/browse/AMQ-3982 Instead of locking on the PList iterator which forces a lock on every access to hasNext we should lock down at the PageFile level in readPage making the seek and read an atomic operation. Since many reads on a single already loaded page don't need to be synchronized we pay a higher price for locking in the specific PList case than we do buy creating this atomic read operation in PageFile. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1375852 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/activemq/store/kahadb/plist/PList.java | 4 +--- .../main/java/org/apache/kahadb/page/PageFile.java | 13 +++++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/store/kahadb/plist/PList.java b/activemq-core/src/main/java/org/apache/activemq/store/kahadb/plist/PList.java index 09fbab2856..953be74cbd 100644 --- a/activemq-core/src/main/java/org/apache/activemq/store/kahadb/plist/PList.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/kahadb/plist/PList.java @@ -202,9 +202,7 @@ public class PList extends ListIndex { @Override public boolean hasNext() { - synchronized (indexLock) { - return iterator.hasNext(); - } + return iterator.hasNext(); } @Override diff --git a/kahadb/src/main/java/org/apache/kahadb/page/PageFile.java b/kahadb/src/main/java/org/apache/kahadb/page/PageFile.java index 77dbf3c723..144cccb934 100644 --- a/kahadb/src/main/java/org/apache/kahadb/page/PageFile.java +++ b/kahadb/src/main/java/org/apache/kahadb/page/PageFile.java @@ -16,7 +16,16 @@ */ package org.apache.kahadb.page; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InterruptedIOException; +import java.io.RandomAccessFile; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -862,7 +871,7 @@ public class PageFile { return nextTxid.incrementAndGet(); } - void readPage(long pageId, byte[] data) throws IOException { + synchronized void readPage(long pageId, byte[] data) throws IOException { readFile.seek(toOffset(pageId)); readFile.readFully(data); }