Browse Source

Code refinement for JDK-picked classes (#1014)

master
于玉桔 Eric Zhao 5 years ago
parent
commit
1253471078
2 changed files with 8 additions and 0 deletions
  1. +6
    -0
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/base/LongAdder.java
  2. +2
    -0
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/base/Striped64.java

+ 6
- 0
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/base/LongAdder.java View File

@@ -46,6 +46,7 @@ public class LongAdder extends Striped64 implements Serializable {
/**
* Version of plus for use in retryUpdate
*/
@Override
final long fn(long v, long x) { return v + x; }

/**
@@ -153,6 +154,7 @@ public class LongAdder extends Striped64 implements Serializable {
*
* @return the String representation of the {@link #sum}
*/
@Override
public String toString() {
return Long.toString(sum());
}
@@ -162,6 +164,7 @@ public class LongAdder extends Striped64 implements Serializable {
*
* @return the sum
*/
@Override
public long longValue() {
return sum();
}
@@ -170,6 +173,7 @@ public class LongAdder extends Striped64 implements Serializable {
* Returns the {@link #sum} as an {@code int} after a narrowing
* primitive conversion.
*/
@Override
public int intValue() {
return (int)sum();
}
@@ -178,6 +182,7 @@ public class LongAdder extends Striped64 implements Serializable {
* Returns the {@link #sum} as a {@code float}
* after a widening primitive conversion.
*/
@Override
public float floatValue() {
return (float)sum();
}
@@ -186,6 +191,7 @@ public class LongAdder extends Striped64 implements Serializable {
* Returns the {@link #sum} as a {@code double} after a widening
* primitive conversion.
*/
@Override
public double doubleValue() {
return (double)sum();
}


+ 2
- 0
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/base/Striped64.java View File

@@ -136,6 +136,7 @@ abstract class Striped64 extends Number {
* The corresponding ThreadLocal class
*/
static final class ThreadHashCode extends ThreadLocal<HashCode> {
@Override
public HashCode initialValue() { return new HashCode(); }
}

@@ -330,6 +331,7 @@ abstract class Striped64 extends Number {
return java.security.AccessController.doPrivileged
(new java.security
.PrivilegedExceptionAction<sun.misc.Unsafe>() {
@Override
public sun.misc.Unsafe run() throws Exception {
java.lang.reflect.Field f = sun.misc
.Unsafe.class.getDeclaredField("theUnsafe");


Loading…
Cancel
Save