< prev index next >
src/com/sun/xml/internal/stream/util/ThreadLocalBufferAllocator.java
Print this page
rev 1955 : 8212178: Soft reference reclamation race in com.sun.xml.internal.stream.util.ThreadLocalBufferAllocator
Reviewed-by: rkennke, kbarrett, joehw
*** 1,7 ****
/*
! * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 37,53 ****
*
* @author Binu.John@sun.com
* @author Santiago.PericasGeertsen@sun.com
*/
public class ThreadLocalBufferAllocator {
! private static ThreadLocal tlba = new ThreadLocal();
public static BufferAllocator getBufferAllocator() {
! SoftReference bAllocatorRef = (SoftReference) tlba.get();
! if (bAllocatorRef == null || bAllocatorRef.get() == null) {
! bAllocatorRef = new SoftReference(new BufferAllocator());
! tlba.set(bAllocatorRef);
}
!
! return (BufferAllocator) bAllocatorRef.get();
}
}
--- 37,57 ----
*
* @author Binu.John@sun.com
* @author Santiago.PericasGeertsen@sun.com
*/
public class ThreadLocalBufferAllocator {
! private static final ThreadLocal<SoftReference<BufferAllocator>> TL = new ThreadLocal<>();
public static BufferAllocator getBufferAllocator() {
! BufferAllocator ba = null;
! SoftReference<BufferAllocator> sr = TL.get();
! if (sr != null) {
! ba = sr.get();
}
! if (ba == null) {
! ba = new BufferAllocator();
! sr = new SoftReference<>(ba);
! TL.set(sr);
! }
! return ba;
}
}
< prev index next >