Skip to content
Permalink
Browse files
Make the thread bus holders final so the jit can optimize the accesse…
…s better.

git-svn-id: https://svn.apache.org/repos/asf/cxf/trunk@1541140 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
dkulp committed Nov 12, 2013
1 parent b94129c commit b5c38cc0e779ce45e3e2c03e0c62c8a5a767d986
Showing 1 changed file with 22 additions and 22 deletions.
@@ -73,8 +73,8 @@ static class BusHolder {
volatile boolean stale;
}

protected static Map<Thread, BusHolder> threadBusses = new WeakHashMap<Thread, BusHolder>();
protected static ThreadLocal<BusHolder> threadBus = new ThreadLocal<BusHolder>();
protected static final Map<Thread, BusHolder> THREAD_BUSSES = new WeakHashMap<Thread, BusHolder>();
protected static final ThreadLocal<BusHolder> THREAD_BUS = new ThreadLocal<BusHolder>();

private static final Logger LOG = LogUtils.getL7dLogger(BusFactory.class);

@@ -114,21 +114,21 @@ public static synchronized Bus getDefaultBus(boolean createIfNeeded) {
}

private static BusHolder getThreadBusHolder(boolean set) {
BusHolder h = threadBus.get();
BusHolder h = THREAD_BUS.get();
if (h == null || h.stale) {
Thread cur = Thread.currentThread();
synchronized (threadBusses) {
h = threadBusses.get(cur);
synchronized (THREAD_BUSSES) {
h = THREAD_BUSSES.get(cur);
}
if (h == null || h.stale) {
h = new BusHolder();

synchronized (threadBusses) {
threadBusses.put(cur, h);
synchronized (THREAD_BUSSES) {
THREAD_BUSSES.put(cur, h);
}
}
if (set) {
threadBus.set(h);
THREAD_BUS.set(h);
}
}
return h;
@@ -146,7 +146,7 @@ public static synchronized void setDefaultBus(Bus bus) {
b.bus = bus;
if (bus == null) {
b.stale = true;
threadBus.remove();
THREAD_BUS.remove();
}
}

@@ -157,17 +157,17 @@ public static synchronized void setDefaultBus(Bus bus) {
*/
public static void setThreadDefaultBus(Bus bus) {
if (bus == null) {
BusHolder h = threadBus.get();
BusHolder h = THREAD_BUS.get();
if (h == null) {
Thread cur = Thread.currentThread();
synchronized (threadBusses) {
h = threadBusses.get(cur);
synchronized (THREAD_BUSSES) {
h = THREAD_BUSSES.get(cur);
}
}
if (h != null) {
h.bus = null;
h.stale = true;
threadBus.remove();
THREAD_BUS.remove();
}
} else {
BusHolder b = getThreadBusHolder(true);
@@ -183,18 +183,18 @@ public static void setThreadDefaultBus(Bus bus) {
*/
public static Bus getAndSetThreadDefaultBus(Bus bus) {
if (bus == null) {
BusHolder b = threadBus.get();
BusHolder b = THREAD_BUS.get();
if (b == null) {
Thread cur = Thread.currentThread();
synchronized (threadBusses) {
b = threadBusses.get(cur);
synchronized (THREAD_BUSSES) {
b = THREAD_BUSSES.get(cur);
}
}
if (b != null) {
Bus orig = b.bus;
b.bus = null;
b.stale = true;
threadBus.remove();
THREAD_BUS.remove();
return orig;
}
return null;
@@ -228,11 +228,11 @@ public static Bus getThreadDefaultBus(boolean createIfNeeded) {
}
return b.bus;
}
BusHolder h = threadBus.get();
BusHolder h = THREAD_BUS.get();
if (h == null || h.stale) {
Thread cur = Thread.currentThread();
synchronized (threadBusses) {
h = threadBusses.get(cur);
synchronized (THREAD_BUSSES) {
h = THREAD_BUSSES.get(cur);
}
}
return h == null || h.stale ? null : h.bus;
@@ -254,8 +254,8 @@ private static synchronized Bus createThreadBus() {
* @param bus the bus to remove
*/
public static void clearDefaultBusForAnyThread(final Bus bus) {
synchronized (threadBusses) {
for (final Iterator<BusHolder> iterator = threadBusses.values().iterator();
synchronized (THREAD_BUSSES) {
for (final Iterator<BusHolder> iterator = THREAD_BUSSES.values().iterator();
iterator.hasNext();) {
BusHolder itBus = iterator.next();
if (bus == null || itBus == null || itBus.bus == null

0 comments on commit b5c38cc

Please sign in to comment.