{"id":37273,"date":"2023-12-11T14:40:50","date_gmt":"2023-12-11T06:40:50","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=37273"},"modified":"2023-12-11T14:40:50","modified_gmt":"2023-12-11T06:40:50","slug":"%e8%ae%b2%e8%ae%b2-atomicinteger-%e7%9a%84%e4%bd%bf%e7%94%a8%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/12\/11\/%e8%ae%b2%e8%ae%b2-atomicinteger-%e7%9a%84%e4%bd%bf%e7%94%a8%ef%bc%9f\/","title":{"rendered":"\u8bb2\u8bb2 AtomicInteger \u7684\u4f7f\u7528\uff1f"},"content":{"rendered":"<p>&#8220;`&#8221;<\/p>\n<p>&lt;pre&gt;public final int get() \/\/\u83b7\u53d6\u5f53\u524d\u7684\u503cpublic final int getAndSet(int newValue)\/\/\u83b7\u53d6\u5f53\u524d\u7684\u503c\uff0c\u5e76\u8bbe\u7f6e\u65b0\u7684\u503cpublic final int getAndIncrement()\/\/\u83b7\u53d6\u5f53\u524d\u7684\u503c\uff0c\u5e76\u81ea\u589epublic final int getAndDecrement() \/\/\u83b7\u53d6\u5f53\u524d\u7684\u503c\uff0c\u5e76\u81ea\u51cfpublic final int getAndAdd(int delta) \/\/\u83b7\u53d6\u5f53\u524d\u7684\u503c\uff0c\u5e76\u52a0\u4e0a\u9884\u671f\u7684\u503cboolean compareAndSet(int expect, int update) \/\/\u5982\u679c\u8f93\u5165\u7684\u6570\u503c\u7b49\u4e8e\u9884\u671f\u503c\uff0c\u5219\u4ee5\u539f\u5b50\u65b9\u5f0f\u5c06\u8be5\u503c\u8bbe\u7f6e\u4e3a\u8f93\u5165\u503c\uff08update\uff09public final void lazySet(int newValue)\/\/\u6700\u7ec8\u8bbe\u7f6e\u4e3anewValue,\u4f7f\u7528 lazySet \u8bbe\u7f6e\u4e4b\u540e\u53ef\u80fd\u5bfc\u81f4\u5176\u4ed6\u7ebf\u7a0b\u5728\u4e4b\u540e\u7684\u4e00\u5c0f\u6bb5\u65f6\u95f4\u5185\u8fd8\u662f\u53ef\u4ee5\u8bfb\u5230\u65e7\u7684\u503c\u3002&lt;\/pre&gt;<\/p>\n<p>&lt;br&gt;<\/p>\n<p>&lt;pre&gt;&lt;code&gt;import java.util.concurrent.atomic.AtomicInteger;public class AtomicIntegerTest {public static void main(String[] args) {\t\/\/ TODO Auto-generated method stub\tint temvalue = 0;\tAtomicInteger i = new AtomicInteger(0);\ttemvalue = i.getAndSet(3);\tSystem.out.println(&quot;&quot;temvalue:&quot;&quot; + temvalue + &quot;&quot;;  i:&quot;&quot; + i);\/\/temvalue:0;  i:3\ttemvalue = i.getAndIncrement();\tSystem.out.println(&quot;&quot;temvalue:&quot;&quot; + temvalue + &quot;&quot;;  i:&quot;&quot; + i);\/\/temvalue:3;  i:4\ttemvalue = i.getAndAdd(5);\tSystem.out.println(&quot;&quot;temvalue:&quot;&quot; + temvalue + &quot;&quot;;  i:&quot;&quot; + i);\/\/temvalue:4;  i:9}}&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>&lt;pre&gt;&lt;code&gt;            &quot;&#8220;`<br \/>\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;`&#8221; &lt;pre&gt;public final int get() \/\/\u83b7\u53d6\u5f53 [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-37273","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/37273","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=37273"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/37273\/revisions"}],"predecessor-version":[{"id":37274,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/37273\/revisions\/37274"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=37273"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=37273"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=37273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}