今天學習LongAdder類,該類是JUC原子包中的類,通過單元測試代碼把所有public api方法跑了一遍,大致瞭解了底層實現
package test.java.util.concurrent.atomic;
import java.util.concurrent.atomic.LongAdder;
import org.junit.Test;
/**
* LongAdder的測試類
*
* @author zqw
* @date 2020-06-21 00:00:10
*/
public class LongAdderTest {
/**
* 無參構造函數
* void
* @Param
* @author zhqwm
* @date 2020/6/20 23:52
*/
@Test
public void testConstruct0()throws Exception{
LongAdder testObj=new LongAdder();
System.out.println(testObj.toString());
}
/**
* 加上對應參數值
* void
* @Param
* @author zhqwm
* @date 2020/6/20 23:52
*/
@Test
public void testAdd(){
LongAdder testObj=new LongAdder();
testObj.add(32);
System.out.println(testObj.toString());
}
/**
* 加一操作
* void
* @Param
* @author zhqwm
* @date 2020/6/20 23:52
*/
@Test
public void testIncrement(){
LongAdder testObj=new LongAdder();
testObj.increment();
System.out.println(testObj.toString());
}
/**
* 減一操作
* void
* @Param
* @author zhqwm
* @date 2020/6/20 23:52
*/
@Test
public void testDecrement(){
LongAdder testObj=new LongAdder();
testObj.decrement();
System.out.println(testObj.toString());
}
/**
* 求和
* void
* @Param
* @author zhqwm
* @date 2020/6/20 23:52
*/
@Test
public void testSum(){
LongAdder testObj=new LongAdder();
testObj.add(32);
System.out.println(testObj.sum());
System.out.println(testObj.toString());
}
/**
* 重置
* void
* @Param
* @author zhqwm
* @date 2020/6/20 23:52
*/
@Test
public void testReset(){
LongAdder testObj=new LongAdder();
testObj.add(32);
System.out.println(testObj.toString());
testObj.reset();
System.out.println(testObj.toString());
}
/**
* 求和然後重置
* void
* @Param
* @author zhqwm
* @date 2020/6/20 23:52
*/
@Test
public void testSumThenReset(){
LongAdder testObj=new LongAdder();
testObj.add(32);
System.out.println(testObj.sumThenReset());
System.out.println(testObj.toString());
}
/**
* toString
* void
* @Param
* @author zhqwm
* @date 2020/6/20 23:52
*/
@Test
public void testToString(){
LongAdder testObj=new LongAdder();
System.out.println(testObj.toString());
}
/**
* 獲取long值
* void
* @Param
* @author zhqwm
* @date 2020/6/20 23:52
*/
@Test
public void testLongValue(){
LongAdder testObj=new LongAdder();
System.out.println(testObj.longValue());
}
/**
* 獲取int值
* void
* @Param
* @author zhqwm
* @date 2020/6/20 23:52
*/
@Test
public void testIntValue(){
LongAdder testObj=new LongAdder();
System.out.println(testObj.intValue());
}
/**
* 獲取float值
* void
* @Param
* @author zhqwm
* @date 2020/6/20 23:52
*/
@Test
public void testFloatValue(){
LongAdder testObj=new LongAdder();
System.out.println(testObj.floatValue());
}
/**
* 獲取double值
* void
* @Param
* @author zhqwm
* @date 2020/6/20 23:52
*/
@Test
public void testDoubleValue(){
LongAdder testObj=new LongAdder();
System.out.println(testObj.doubleValue());
}
}