public class DoubleAccumulator extends Number implements Serializable
double值更新,使用提供的功能。当更新(方法
accumulate(double))主张跨线程、变量的设置可以动态增长以减少争用。方法
get()(或者,等价地,
doubleValue())返回当前值在变量保持更新。
这个类通常是最好的替代方案时,多个线程更新一个共同的价值,是用来的目的,如汇总统计,经常更新,但不经常阅读。
所提供的蓄电池功能应该是免费的,因为它可能被重新应用时尝试更新失败,由于线程之间的争用。函数以当前值作为其第一个参数,并且给出的更新作为第二个参数。例如,保持最大值,你可以供应Double::max随着Double.NEGATIVE_INFINITY身份。在或跨线程内的积累的顺序是不保证。因此,这个类可能不适用,如果需要的数值稳定性,特别是当结合的值的基本上不同的数量级。
类DoubleAdder提供维护和常见的特殊情况,这一类的功能类似物。电话new DoubleAdder()相当于new DoubleAccumulator((x, y) -> x + y, 0.0)。
这类Number延伸,但不定义方法如equals,hashCode和compareTo因为情况预计将发生突变,而不是用作收集钥匙。
| Constructor and Description |
|---|
DoubleAccumulator(DoubleBinaryOperator accumulatorFunction, double identity)
使用给定的“生成”函数和标识元素创建一个新实例。
|
| Modifier and Type | Method and Description |
|---|---|
void |
accumulate(double x)
具有给定值的更新。
|
double |
doubleValue()
相当于
get()。
|
float |
floatValue()
作为一个窄化转换后
float返回
current value。
|
double |
get()
返回当前值。
|
double |
getThenReset()
|
int |
intValue()
作为一个窄化转换后,
int返回
current value。
|
long |
longValue()
作为一个窄化转换后
long返回
current value。
|
void |
reset()
重置变量保持更新的价值认同。
|
String |
toString()
返回当前值的字符串表示形式。
|
byteValue, shortValuepublic DoubleAccumulator(DoubleBinaryOperator accumulatorFunction, double identity)
accumulatorFunction -两参数无副作用的功能
identity身份(初始值)为蓄能器的功能
public void accumulate(double x)
x -价值
public double get()
public void reset()
public double getThenReset()
public double doubleValue()
get()。
doubleValue 方法重写,继承类
Number
public long longValue()
long返回
current value。
public int intValue()
int返回
current value。
public float floatValue()
float返回
current value。
floatValue 方法重写,继承类
Number
float后。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.