AtomicInteger t1 = new AtomicInteger();
时间: 2023-10-19 10:27:27 浏览: 86
java synchronized关键字的用法
AtomicInteger t1 = new AtomicInteger()是创建一个初始值为0的AtomicInteger对象。AtomicInteger是Java并发包中提供的原子类,用于对int类型的整数进行原子操作。它使用底层的CAS(Compare and Swap)等方法来实现原子操作。CAS是一种乐观锁技术,它通过比较内存中的值与期望值来判断是否需要更新,并在需要时进行更新。因此,使用AtomicInteger的incrementAndGet方法可以保证对t1进行原子操作,即每次对t1进行自增操作时都能保证线程安全。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [AtomicInteger原理](https://blog.csdn.net/weixin_35411443/article/details/114511648)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [Java原子类应用场景如:AtomicInteger的使用](https://blog.csdn.net/qq_35222843/article/details/114314657)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [java并发之AtomicInteger源码分析](https://download.csdn.net/download/weixin_38606076/12749202)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文