在构造函数中计算remain值时,是否需要进行synchronize减法运算?
public OrderFillSummary(final BigDecimal total, final BigDecimal filled) {
AssertUtils.isGtZero(total, "total");
AssertUtils.isGtZero(filled, "filled");
this.total = total;
this.filled = filled;
this.remain = this.total.subtract(this.filled);
}发布于 2021-02-20 01:22:29
BigDecimal (和BigInteger)是不可变的,而且你是在一个构造函数中,所以,基本上,不是--尽管你的问题缺乏很多细节。如果甚至涉及到多个线程(如果没有,则synchronize用于多个线程),那么解释如何,尽管我可以想象您可能会说的任何话都会导致答案:不,您不需要这样做。
https://stackoverflow.com/questions/66282117
复制相似问题