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)
使用给定的累加器函数和identity元素创建一个新的实例。
|
| Modifier and Type | Method and Description |
|---|---|
void |
accumulate(double x)
具有给定值的更新。
|
double |
doubleValue()
相当于
get() 。
|
float |
floatValue()
|
double |
get()
返回当前值。
|
double |
getThenReset()
|
int |
intValue()
|
long |
longValue()
|
void |
reset()
重置维持更新到标识值的变量。
|
String |
toString()
返回当前值的String表示形式。
|
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 float floatValue()
floatValue在类别
Number
float之后表示的
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.