Skip to content

Commit ec8dfb8

Browse files
hansonrhansonr
authored andcommitted
removing ThreadLocal references
1 parent 54029d9 commit ec8dfb8

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

sources/net.sf.j2s.java.core/src/java/util/concurrent/ThreadLocalRandom.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,13 @@ private static long initialSeed() {
169169
private static final float FLOAT_UNIT = 0x1.0p-24f; // 1.0f / (1 << 24)
170170

171171
/** Rarely-used holder for the second of a pair of Gaussians */
172-
private static final ThreadLocal<Double> nextLocalGaussian =
173-
new ThreadLocal<Double>();
172+
private static
173+
//final ThreadLocal<
174+
Double
175+
//>
176+
nextLocalGaussian
177+
//= new ThreadLocal<Double()>
178+
;
174179

175180
private static long mix64(long z) {
176181
z = (z ^ (z >>> 33)) * 0xff51afd7ed558ccdL;
@@ -498,9 +503,9 @@ public float nextFloat() {
498503

499504
public double nextGaussian() {
500505
// Use nextLocalGaussian instead of nextGaussian field
501-
Double d = nextLocalGaussian.get();
506+
Double d = nextLocalGaussian;//.get();
502507
if (d != null) {
503-
nextLocalGaussian.set(null);
508+
nextLocalGaussian = /*.set*/(null);
504509
return d.doubleValue();
505510
}
506511
double v1, v2, s;
@@ -510,7 +515,7 @@ public double nextGaussian() {
510515
s = v1 * v1 + v2 * v2;
511516
} while (s >= 1 || s == 0);
512517
double multiplier = StrictMath.sqrt(-2 * StrictMath.log(s)/s);
513-
nextLocalGaussian.set(new Double(v2 * multiplier));
518+
nextLocalGaussian/*.set*/=(new Double(v2 * multiplier));
514519
return v1 * multiplier;
515520
}
516521

sources/net.sf.j2s.java.core/src/sun/nio/cs/ThreadLocalCoders.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626

2727
package sun.nio.cs;
2828

29-
import java.nio.charset.*;
29+
import java.nio.charset.Charset;
30+
import java.nio.charset.CharsetDecoder;
31+
import java.nio.charset.CharsetEncoder;
3032

3133

3234
/**
@@ -40,7 +42,10 @@ public class ThreadLocalCoders {
4042
private static abstract class Cache {
4143

4244
// Thread-local reference to array of cached objects, in LRU order
43-
private ThreadLocal<Object[]> cache = new ThreadLocal<>();
45+
// private ThreadLocal<Object[]> cache = new ThreadLocal<>();
46+
47+
private Object[] cache;
48+
4449
private final int size;
4550

4651
Cache(int size) {
@@ -50,7 +55,7 @@ private static abstract class Cache {
5055
abstract Object create(Object name);
5156

5257
private void moveToFront(Object[] oa, int i) {
53-
Object ob = oa[i];
58+
Object ob = oa[i];
5459
for (int j = i; j > 0; j--)
5560
oa[j] = oa[j - 1];
5661
oa[0] = ob;
@@ -59,10 +64,10 @@ private void moveToFront(Object[] oa, int i) {
5964
abstract boolean hasName(Object ob, Object name);
6065

6166
Object forName(Object name) {
62-
Object[] oa = cache.get();
67+
Object[] oa = cache;//.get();
6368
if (oa == null) {
6469
oa = new Object[size];
65-
cache.set(oa);
70+
cache = oa;//.set(oa);
6671
} else {
6772
for (int i = 0; i < oa.length; i++) {
6873
Object ob = oa[i];

sources/net.sf.j2s.java.core/src/test/math/BigDecimal.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,13 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
274274
/* Appease the serialization gods */
275275
private static final long serialVersionUID = 6108874887143696463L;
276276

277-
private static final ThreadLocal<StringBuilderHelper>
278-
threadLocalStringBuilderHelper = new ThreadLocal<StringBuilderHelper>() {
277+
private static final /*ThreadLocal<*/StringBuilderHelper/*>*/
278+
threadLocalStringBuilderHelper = new /*ThreadLocal<*/StringBuilderHelper/*>*/() /*{
279279
@Override
280280
protected StringBuilderHelper initialValue() {
281281
return new StringBuilderHelper();
282282
}
283-
};
283+
}*/;
284284

285285
// Cache of common small BigDecimal values.
286286
private static final BigDecimal zeroThroughTen[] = {
@@ -3437,7 +3437,7 @@ private String layoutChars(boolean sci) {
34373437
StringBuilderHelper.DIGIT_ONES[lowInt]) ;
34383438
}
34393439

3440-
StringBuilderHelper sbHelper = threadLocalStringBuilderHelper.get();
3440+
StringBuilderHelper sbHelper = threadLocalStringBuilderHelper;//.get();
34413441
char[] coeff;
34423442
int offset; // offset is the starting index for coeff array
34433443
// Get the significand as an absolute value
@@ -3465,7 +3465,7 @@ private String layoutChars(boolean sci) {
34653465
buf.append('.');
34663466
for (; pad>0; pad--) {
34673467
buf.append('0');
3468-
}
3468+
}
34693469
buf.append(coeff, offset, coeffLen);
34703470
} else { // xx.xx form
34713471
buf.append(coeff, offset, -pad);

0 commit comments

Comments
 (0)