{"id":71142,"date":"2026-02-03T09:24:41","date_gmt":"2026-02-03T01:24:41","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/71142.html"},"modified":"2026-02-03T09:24:41","modified_gmt":"2026-02-03T01:24:41","slug":"java%e5%b9%b6%e5%8f%91%e7%bc%96%e7%a8%8b%e5%9f%ba%e7%a1%80%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/71142.html","title":{"rendered":"Java\u5e76\u53d1\u7f16\u7a0b\u57fa\u7840\u89e3\u6790"},"content":{"rendered":"<h3 id=\"toc-7401e37d3a8718f4bc839a595b116e15\">\u4e00\u3001\u5f15\u8a00<\/h3>\n<\/p>\n<p>\u5728\u5f53\u4eca\u8ba1\u7b97\u673a\u786c\u4ef6\u98de\u901f\u53d1\u5c55\u7684\u80cc\u666f\u4e0b&#xff0c;\u591a\u6838\u5904\u7406\u5668\u5df2\u7ecf\u6210\u4e3a\u6807\u51c6\u914d\u7f6e\u3002\u5982\u4f55\u5145\u5206\u5229\u7528\u591a\u6838CPU\u7684\u8ba1\u7b97\u80fd\u529b&#xff0c;\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u54cd\u5e94\u901f\u5ea6&#xff0c;\u6210\u4e3a\u6bcf\u4e2aJava\u5f00\u53d1\u8005\u5fc5\u987b\u638c\u63e1\u7684\u6838\u5fc3\u6280\u80fd\u3002\u5e76\u53d1\u7f16\u7a0b\u4f5c\u4e3a\u63d0\u5347\u7a0b\u5e8f\u6027\u80fd\u7684\u91cd\u8981\u624b\u6bb5&#xff0c;\u5728Java\u751f\u6001\u7cfb\u7edf\u4e2d\u5360\u636e\u7740\u91cd\u8981\u5730\u4f4d\u3002<\/p>\n<\/p>\n<p>Java\u4ece\u8bde\u751f\u4e4b\u521d\u5c31\u5c06\u591a\u7ebf\u7a0b\u652f\u6301\u4f5c\u4e3a\u6838\u5fc3\u7279\u6027\u4e4b\u4e00&#xff0c;\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5e76\u53d1\u7f16\u7a0bAPI\u548c\u5de5\u5177\u7c7b\u3002\u4ece\u57fa\u7840\u7684Thread\u7c7b\u5230\u9ad8\u7ea7\u7684\u5e76\u53d1\u96c6\u5408&#xff0c;\u4ece\u7b80\u5355\u7684\u540c\u6b65\u673a\u5236\u5230\u590d\u6742\u7684\u5e76\u53d1\u6846\u67b6&#xff0c;Java\u4e3a\u5f00\u53d1\u8005\u6784\u5efa\u9ad8\u6027\u80fd\u5e76\u53d1\u5e94\u7528\u63d0\u4f9b\u4e86\u5b8c\u6574\u7684\u6280\u672f\u6808\u3002\u638c\u63e1Java\u5e76\u53d1\u7f16\u7a0b\u4e0d\u4ec5\u662f\u6280\u672f\u6df1\u5ea6\u7684\u4f53\u73b0&#xff0c;\u66f4\u662f\u89e3\u51b3\u5b9e\u9645\u6027\u80fd\u95ee\u9898\u7684\u5173\u952e\u80fd\u529b\u3002<\/p>\n<\/p>\n<h3 id=\"toc-5f6c808f107c23636cc221f95aef897d\">\u4e8c\u3001\u6838\u5fc3\u6982\u5ff5<\/h3>\n<\/p>\n<h4 id=\"toc-903168d9c6ce3791f7a7113d51078aea\">2.1 \u8fdb\u7a0b\u4e0e\u7ebf\u7a0b<\/h4>\n<\/p>\n<p>\u8fdb\u7a0b\u662f\u64cd\u4f5c\u7cfb\u7edf\u8d44\u6e90\u5206\u914d\u7684\u57fa\u672c\u5355\u4f4d&#xff0c;\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u6709\u72ec\u7acb\u7684\u5185\u5b58\u7a7a\u95f4\u548c\u7cfb\u7edf\u8d44\u6e90\u3002\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u5305\u542b\u591a\u4e2a\u8fdb\u7a0b\u3002<\/p>\n<\/p>\n<p>\u7ebf\u7a0b\u662fCPU\u8c03\u5ea6\u7684\u57fa\u672c\u5355\u4f4d&#xff0c;\u4e5f\u88ab\u79f0\u4e3a\u8f7b\u91cf\u7ea7\u8fdb\u7a0b\u3002\u540c\u4e00\u8fdb\u7a0b\u5185\u7684\u7ebf\u7a0b\u5171\u4eab\u8fdb\u7a0b\u7684\u5185\u5b58\u7a7a\u95f4\u548c\u8d44\u6e90&#xff0c;\u4f46\u62e5\u6709\u72ec\u7acb\u7684\u7a0b\u5e8f\u8ba1\u6570\u5668\u3001\u6808\u548c\u5c40\u90e8\u53d8\u91cf\u3002<\/p>\n<p>\/\/ \u8fdb\u7a0b\u4e0e\u7ebf\u7a0b\u7684\u533a\u522b\u793a\u4f8b<br \/>\npublic class ProcessThreadDemo {<br \/>\n    public static void main(String[] args) {<br \/>\n        \/\/ main\u65b9\u6cd5\u672c\u8eab\u5c31\u662f\u4e00\u4e2a\u7ebf\u7a0b<br \/>\n        System.out.println(&#034;\u4e3b\u7ebf\u7a0b\u540d\u79f0: &#034; &#043; Thread.currentThread().getName());<\/p>\n<p>        \/\/ \u521b\u5efa\u5e76\u542f\u52a8\u65b0\u7ebf\u7a0b<br \/>\n        Thread newThread &#061; new Thread(() -&gt; {<br \/>\n            System.out.println(&#034;\u65b0\u7ebf\u7a0b\u540d\u79f0: &#034; &#043; Thread.currentThread().getName());<br \/>\n        });<br \/>\n        newThread.start();<br \/>\n    }<br \/>\n}<\/p>\n<h4 id=\"toc-a595bae6d26ec63e47190da88fd6dc3d\">2.2 \u5e76\u53d1\u4e0e\u5e76\u884c<\/h4>\n<\/p>\n<p>\u5e76\u53d1\u662f\u6307\u591a\u4e2a\u4efb\u52a1\u5728\u540c\u4e00\u4e2a\u65f6\u95f4\u6bb5\u5185\u4ea4\u66ff\u6267\u884c&#xff0c;\u5b8f\u89c2\u4e0a\u770b\u8d77\u6765\u662f\u540c\u65f6\u8fdb\u884c&#xff0c;\u4f46\u5fae\u89c2\u4e0a\u662f\u4ea4\u66ff\u4f7f\u7528CPU\u8d44\u6e90\u3002<\/p>\n<\/p>\n<p>\u5e76\u884c\u662f\u6307\u591a\u4e2a\u4efb\u52a1\u771f\u6b63\u5728\u540c\u4e00\u65f6\u523b\u6267\u884c&#xff0c;\u9700\u8981\u591a\u6838CPU\u652f\u6301\u3002<\/p>\n<p>\u5e76\u53d1\u6a21\u5f0f&#xff08;\u5355\u6838CPU&#xff09;:<br \/>\n\u65f6\u95f4\u72471: \u4efb\u52a1A<br \/>\n\u65f6\u95f4\u72472: \u4efb\u52a1B<br \/>\n\u65f6\u95f4\u72473: \u4efb\u52a1A<br \/>\n\u65f6\u95f4\u72474: \u4efb\u52a1B<\/p>\n<p>\u5e76\u884c\u6a21\u5f0f&#xff08;\u591a\u6838CPU&#xff09;:<br \/>\n\u6838\u5fc31: \u4efb\u52a1A (\u6301\u7eed\u6267\u884c)<br \/>\n\u6838\u5fc32: \u4efb\u52a1B (\u6301\u7eed\u6267\u884c)<\/p>\n<h3 id=\"toc-c7a3712f56957eaa34f8982fd9826984\">\u4e09\u3001Java\u5e76\u53d1\u57fa\u7840<\/h3>\n<\/p>\n<h4 id=\"toc-5a55bc4f5bbc3c9e354a797f1fc40266\">3.1 Thread\u7c7b\u4e0eRunnable\u63a5\u53e3<\/h4>\n<\/p>\n<p>Java\u63d0\u4f9b\u4e86\u4e24\u79cd\u4e3b\u8981\u7684\u7ebf\u7a0b\u521b\u5efa\u65b9\u5f0f&#xff1a;\u7ee7\u627fThread\u7c7b\u548c\u5b9e\u73b0Runnable\u63a5\u53e3\u3002<\/p>\n<p>\/\/ \u65b9\u5f0f\u4e00&#xff1a;\u7ee7\u627fThread\u7c7b<br \/>\nclass MyThread extends Thread {<br \/>\n    &#064;Override<br \/>\n    public void run() {<br \/>\n        for (int i &#061; 0; i &lt; 5; i&#043;&#043;) {<br \/>\n            System.out.println(Thread.currentThread().getName() &#043; &#034;: &#034; &#043; i);<br \/>\n            try {<br \/>\n                Thread.sleep(500); \/\/ \u7ebf\u7a0b\u4f11\u7720500\u6beb\u79d2<br \/>\n            } catch (InterruptedException e) {<br \/>\n                e.printStackTrace();<br \/>\n            }<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ \u65b9\u5f0f\u4e8c&#xff1a;\u5b9e\u73b0Runnable\u63a5\u53e3<br \/>\nclass MyRunnable implements Runnable {<br \/>\n    &#064;Override<br \/>\n    public void run() {<br \/>\n        for (int i &#061; 0; i &lt; 5; i&#043;&#043;) {<br \/>\n            System.out.println(Thread.currentThread().getName() &#043; &#034;: &#034; &#043; i);<br \/>\n            try {<br \/>\n                Thread.sleep(500);<br \/>\n            } catch (InterruptedException e) {<br \/>\n                e.printStackTrace();<br \/>\n            }<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>public class ThreadCreationDemo {<br \/>\n    public static void main(String[] args) {<br \/>\n        \/\/ \u4f7f\u7528Thread\u7c7b\u521b\u5efa\u7ebf\u7a0b<br \/>\n        MyThread thread1 &#061; new MyThread();<br \/>\n        thread1.setName(&#034;Thread-\u65b9\u5f0f\u4e00&#034;);<br \/>\n        thread1.start(); \/\/ \u542f\u52a8\u7ebf\u7a0b&#xff0c;\u4e0d\u8981\u76f4\u63a5\u8c03\u7528run()\u65b9\u6cd5<\/p>\n<p>        \/\/ \u4f7f\u7528Runnable\u63a5\u53e3\u521b\u5efa\u7ebf\u7a0b<br \/>\n        MyRunnable runnable &#061; new MyRunnable();<br \/>\n        Thread thread2 &#061; new Thread(runnable);<br \/>\n        thread2.setName(&#034;Thread-\u65b9\u5f0f\u4e8c&#034;);<br \/>\n        thread2.start();<\/p>\n<p>        \/\/ \u4f7f\u7528Lambda\u8868\u8fbe\u5f0f\u7b80\u5316Runnable\u5b9e\u73b0&#xff08;\u63a8\u8350&#xff09;<br \/>\n        Thread thread3 &#061; new Thread(() -&gt; {<br \/>\n            for (int i &#061; 0; i &lt; 5; i&#043;&#043;) {<br \/>\n                System.out.println(&#034;Lambda\u7ebf\u7a0b: &#034; &#043; i);<br \/>\n                try {<br \/>\n                    Thread.sleep(500);<br \/>\n                } catch (InterruptedException e) {<br \/>\n                    e.printStackTrace();<br \/>\n                }<br \/>\n            }<br \/>\n        });<br \/>\n        thread3.start();<br \/>\n    }<br \/>\n}<\/p>\n<h4 id=\"toc-05620002fabbf5f42d23187d9e1307fd\">3.2 \u7ebf\u7a0b\u751f\u547d\u5468\u671f\u53ca\u72b6\u6001\u8f6c\u6362<\/h4>\n<\/p>\n<p>Java\u7ebf\u7a0b\u67096\u79cd\u72b6\u6001&#xff0c;\u901a\u8fc7Thread.State\u679a\u4e3e\u5b9a\u4e49&#xff1a;<\/p>\n<\/p>\n<li>NEW&#xff08;\u65b0\u5efa&#xff09; &#xff1a;\u7ebf\u7a0b\u88ab\u521b\u5efa\u4f46\u672a\u542f\u52a8<\/li>\n<li>RUNNABLE&#xff08;\u53ef\u8fd0\u884c&#xff09; &#xff1a;\u7ebf\u7a0b\u6b63\u5728JVM\u4e2d\u6267\u884c&#xff0c;\u53ef\u80fd\u5728\u7b49\u5f85CPU\u8d44\u6e90<\/li>\n<li>BLOCKED&#xff08;\u963b\u585e&#xff09; &#xff1a;\u7ebf\u7a0b\u7b49\u5f85\u76d1\u89c6\u5668\u9501\u8fdb\u5165\u540c\u6b65\u5757\/\u65b9\u6cd5<\/li>\n<li>WAITING&#xff08;\u7b49\u5f85&#xff09; &#xff1a;\u7ebf\u7a0b\u65e0\u9650\u671f\u7b49\u5f85\u5176\u4ed6\u7ebf\u7a0b\u6267\u884c\u7279\u5b9a\u64cd\u4f5c<\/li>\n<li>TIMED_WAITING&#xff08;\u8ba1\u65f6\u7b49\u5f85&#xff09; &#xff1a;\u7ebf\u7a0b\u7b49\u5f85\u5176\u4ed6\u7ebf\u7a0b\u6267\u884c\u64cd\u4f5c&#xff0c;\u4f46\u6709\u8d85\u65f6\u65f6\u95f4<\/li>\n<li>TERMINATED&#xff08;\u7ec8\u6b62&#xff09; &#xff1a;\u7ebf\u7a0b\u6267\u884c\u5b8c\u6bd5<\/li>\n<p>public class ThreadStateDemo {<br \/>\n    public static void main(String[] args) throws InterruptedException {<br \/>\n        Thread thread &#061; new Thread(() -&gt; {<br \/>\n            try {<br \/>\n                \/\/ TIMED_WAITING\u72b6\u6001<br \/>\n                Thread.sleep(1000);<br \/>\n                synchronized (ThreadStateDemo.class) {<br \/>\n                    \/\/ BLOCKED\u72b6\u6001&#xff08;\u7b49\u5f85\u9501&#xff09;<br \/>\n                    Thread.sleep(100);<br \/>\n                }<br \/>\n            } catch (InterruptedException e) {<br \/>\n                e.printStackTrace();<br \/>\n            }<br \/>\n        });<\/p>\n<p>        System.out.println(&#034;\u7ebf\u7a0b\u72b6\u6001: &#034; &#043; thread.getState()); \/\/ NEW<\/p>\n<p>        thread.start();<br \/>\n        System.out.println(&#034;\u7ebf\u7a0b\u72b6\u6001: &#034; &#043; thread.getState()); \/\/ RUNNABLE<\/p>\n<p>        Thread.sleep(100);<br \/>\n        System.out.println(&#034;\u7ebf\u7a0b\u72b6\u6001: &#034; &#043; thread.getState()); \/\/ TIMED_WAITING<\/p>\n<p>        thread.join();<br \/>\n        System.out.println(&#034;\u7ebf\u7a0b\u72b6\u6001: &#034; &#043; thread.getState()); \/\/ TERMINATED<br \/>\n    }<br \/>\n}<\/p>\n<h4 id=\"toc-56eb360d602258e6779ca74e2ac31309\">3.3 \u7ebf\u7a0b\u521b\u5efa\u65b9\u5f0f\u5bf9\u6bd4<\/h4>\n<\/p>\n<table>\n<tr>\u7279\u6027\u7ee7\u627fThread\u7c7b\u5b9e\u73b0Runnable\u63a5\u53e3<\/tr>\n<tbody>\n<tr>\n<td>\u5355\u7ee7\u627f\u9650\u5236<\/td>\n<td>\u2717 \u53ea\u80fd\u7ee7\u627f\u4e00\u4e2a\u7c7b<\/td>\n<td>\u2713 \u53ef\u5b9e\u73b0\u591a\u4e2a\u63a5\u53e3<\/td>\n<\/tr>\n<tr>\n<td>\u4ee3\u7801\u8026\u5408\u5ea6<\/td>\n<td>\u9ad8&#xff08;\u4e1a\u52a1\u903b\u8f91\u4e0e\u7ebf\u7a0b\u8026\u5408&#xff09;<\/td>\n<td>\u4f4e&#xff08;\u4e1a\u52a1\u903b\u8f91\u72ec\u7acb&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u8d44\u6e90\u5171\u4eab<\/td>\n<td>\u56f0\u96be<\/td>\n<td>\u5bb9\u6613&#xff08;\u9002\u5408\u5171\u4eab\u8d44\u6e90\u573a\u666f&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u63a8\u8350\u4f7f\u7528<\/td>\n<td>\u4e0d\u63a8\u8350<\/td>\n<td>\u63a8\u8350<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/p>\n<h3 id=\"toc-d15a1b0074939fc1d74e9364dcc56636\">\u56db\u3001\u7ebf\u7a0b\u540c\u6b65\u673a\u5236<\/h3>\n<\/p>\n<h4 id=\"toc-092a388bbf8551ba9ca40e2a3321fdf5\">4.1 synchronized\u5173\u952e\u5b57\u8be6\u89e3<\/h4>\n<\/p>\n<p>synchronized\u662fJava\u4e2d\u6700\u57fa\u672c\u7684\u540c\u6b65\u673a\u5236&#xff0c;\u7528\u4e8e\u89e3\u51b3\u591a\u7ebf\u7a0b\u8bbf\u95ee\u5171\u4eab\u8d44\u6e90\u7684\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898\u3002<\/p>\n<\/p>\n<h5 id=\"toc-35612eaae5bb36955d90a3380e30a17d\">4.1.1 \u540c\u6b65\u65b9\u6cd5<\/h5>\n<p>public class SynchronizedMethodDemo {<br \/>\n    private int counter &#061; 0;<\/p>\n<p>    \/\/ \u540c\u6b65\u5b9e\u4f8b\u65b9\u6cd5<br \/>\n    public synchronized void increment() {<br \/>\n        counter&#043;&#043;;<br \/>\n    }<\/p>\n<p>    \/\/ \u540c\u6b65\u9759\u6001\u65b9\u6cd5<br \/>\n    public static synchronized void staticMethod() {<br \/>\n        System.out.println(&#034;\u540c\u6b65\u9759\u6001\u65b9\u6cd5&#034;);<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) throws InterruptedException {<br \/>\n        SynchronizedMethodDemo demo &#061; new SynchronizedMethodDemo();<\/p>\n<p>        \/\/ \u521b\u5efa\u591a\u4e2a\u7ebf\u7a0b\u5e76\u53d1\u4fee\u6539counter<br \/>\n        Thread[] threads &#061; new Thread[10];<br \/>\n        for (int i &#061; 0; i &lt; threads.length; i&#043;&#043;) {<br \/>\n            threads[i] &#061; new Thread(() -&gt; {<br \/>\n                for (int j &#061; 0; j &lt; 1000; j&#043;&#043;) {<br \/>\n                    demo.increment();<br \/>\n                }<br \/>\n            });<br \/>\n            threads[i].start();<br \/>\n        }<\/p>\n<p>        \/\/ \u7b49\u5f85\u6240\u6709\u7ebf\u7a0b\u6267\u884c\u5b8c\u6210<br \/>\n        for (Thread thread : threads) {<br \/>\n            thread.join();<br \/>\n        }<\/p>\n<p>        System.out.println(&#034;\u6700\u7ec8counter\u503c: &#034; &#043; demo.counter); \/\/ \u5e94\u8be5\u8f93\u51fa10000<br \/>\n    }<br \/>\n}<\/p>\n<h5 id=\"toc-b1ccd4f902dd4f161ddbc11e9b39c307\">4.1.2 \u540c\u6b65\u4ee3\u7801\u5757<\/h5>\n<p>public class SynchronizedBlockDemo {<br \/>\n    private int counter &#061; 0;<br \/>\n    private final Object lock &#061; new Object(); \/\/ \u4e13\u7528\u9501\u5bf9\u8c61<\/p>\n<p>    \/\/ \u4f7f\u7528synchronized\u4ee3\u7801\u5757<br \/>\n    public void increment() {<br \/>\n        synchronized (lock) { \/\/ \u4f7f\u7528\u4e13\u7528\u9501\u5bf9\u8c61<br \/>\n            counter&#043;&#043;;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/ \u540c\u6b65this\u5bf9\u8c61<br \/>\n    public void incrementThis() {<br \/>\n        synchronized (this) {<br \/>\n            counter&#043;&#043;;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/ \u540c\u6b65Class\u5bf9\u8c61<br \/>\n    public static void staticBlockMethod() {<br \/>\n        synchronized (SynchronizedBlockDemo.class) {<br \/>\n            System.out.println(&#034;\u540c\u6b65\u4ee3\u7801\u5757 &#8211; Class\u5bf9\u8c61\u9501&#034;);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) throws InterruptedException {<br \/>\n        SynchronizedBlockDemo demo &#061; new SynchronizedBlockDemo();<\/p>\n<p>        Runnable task &#061; () -&gt; {<br \/>\n            for (int i &#061; 0; i &lt; 1000; i&#043;&#043;) {<br \/>\n                demo.increment();<br \/>\n            }<br \/>\n        };<\/p>\n<p>        Thread thread1 &#061; new Thread(task);<br \/>\n        Thread thread2 &#061; new Thread(task);<\/p>\n<p>        thread1.start();<br \/>\n        thread2.start();<\/p>\n<p>        thread1.join();<br \/>\n        thread2.join();<\/p>\n<p>        System.out.println(&#034;Counter\u503c: &#034; &#043; demo.counter); \/\/ \u5e94\u8be5\u8f93\u51fa2000<br \/>\n    }<br \/>\n}<\/p>\n<h4 id=\"toc-75468ae69575bfb44e0fb3e87bdd0ff0\">4.2 volatile\u5173\u952e\u5b57<\/h4>\n<\/p>\n<p>volatile\u5173\u952e\u5b57\u7528\u4e8e\u786e\u4fdd\u53d8\u91cf\u7684\u53ef\u89c1\u6027\u548c\u6709\u5e8f\u6027&#xff0c;\u4f46\u4e0d\u80fd\u4fdd\u8bc1\u539f\u5b50\u6027\u3002<\/p>\n<p>public class VolatileDemo {<br \/>\n    \/\/ \u4f7f\u7528volatile\u4fdd\u8bc1\u53ef\u89c1\u6027<br \/>\n    private volatile boolean running &#061; true;<br \/>\n    private volatile int counter &#061; 0;<\/p>\n<p>    public void stop() {<br \/>\n        running &#061; false;<br \/>\n    }<\/p>\n<p>    public void startThread() {<br \/>\n        Thread worker &#061; new Thread(() -&gt; {<br \/>\n            while (running) {<br \/>\n                counter&#043;&#043;;<br \/>\n                try {<br \/>\n                    Thread.sleep(100);<br \/>\n                } catch (InterruptedException e) {<br \/>\n                    e.printStackTrace();<br \/>\n                }<br \/>\n            }<br \/>\n            System.out.println(&#034;\u7ebf\u7a0b\u5df2\u505c\u6b62&#xff0c;counter\u503c: &#034; &#043; counter);<br \/>\n        });<\/p>\n<p>        worker.start();<\/p>\n<p>        \/\/ \u4e3b\u7ebf\u7a0b\u4f11\u77202\u79d2\u540e\u505c\u6b62\u5de5\u4f5c\u7ebf\u7a0b<br \/>\n        try {<br \/>\n            Thread.sleep(2000);<br \/>\n        } catch (InterruptedException e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n        stop();<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        VolatileDemo demo &#061; new VolatileDemo();<br \/>\n        demo.startThread();<br \/>\n    }<br \/>\n}<\/p>\n<h4 id=\"toc-2e8bbbc38e46b7ac5c5fdd8f19e645d1\">4.3 \u7ebf\u7a0b\u5b89\u5168\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6848<\/h4>\n<\/p>\n<h5 id=\"toc-a4b67a57a2ff18901575ca660cbf51bc\">4.3.1 \u7ebf\u7a0b\u5b89\u5168\u95ee\u9898\u4ea7\u751f\u539f\u56e0<\/h5>\n<\/p>\n<li>\u539f\u5b50\u6027\u95ee\u9898&#xff1a;\u4e00\u4e2a\u64cd\u4f5c\u4e0d\u80fd\u88ab\u4e2d\u65ad&#xff0c;\u8981\u4e48\u5168\u90e8\u6267\u884c&#xff0c;\u8981\u4e48\u90fd\u4e0d\u6267\u884c<\/li>\n<li>\u53ef\u89c1\u6027\u95ee\u9898&#xff1a;\u4e00\u4e2a\u7ebf\u7a0b\u4fee\u6539\u4e86\u5171\u4eab\u53d8\u91cf\u7684\u503c&#xff0c;\u5176\u4ed6\u7ebf\u7a0b\u4e0d\u80fd\u7acb\u5373\u770b\u5230<\/li>\n<li>\u6709\u5e8f\u6027\u95ee\u9898&#xff1a;\u6307\u4ee4\u91cd\u6392\u5e8f\u5bfc\u81f4\u4ee3\u7801\u6267\u884c\u987a\u5e8f\u4e0e\u9884\u671f\u4e0d\u7b26<\/li>\n<h5 id=\"toc-86863c7e265ddd879be6ee1f94a1e696\">4.3.2 \u7ebf\u7a0b\u5b89\u5168\u793a\u4f8b\u4e0e\u89e3\u51b3\u65b9\u6848<\/h5>\n<p>public class ThreadSafetyDemo {<br \/>\n    \/\/ \u95ee\u9898\u793a\u4f8b&#xff1a;\u975e\u7ebf\u7a0b\u5b89\u5168\u7684\u8ba1\u6570\u5668<br \/>\n    private int unsafeCounter &#061; 0;<\/p>\n<p>    public void unsafeIncrement() {<br \/>\n        unsafeCounter&#043;&#043;; \/\/ \u975e\u539f\u5b50\u64cd\u4f5c&#xff0c;\u5b58\u5728\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898<br \/>\n    }<\/p>\n<p>    \/\/ \u89e3\u51b3\u65b9\u68481&#xff1a;\u4f7f\u7528synchronized<br \/>\n    private int syncCounter &#061; 0;<\/p>\n<p>    public synchronized void syncIncrement() {<br \/>\n        syncCounter&#043;&#043;;<br \/>\n    }<\/p>\n<p>    \/\/ \u89e3\u51b3\u65b9\u68482&#xff1a;\u4f7f\u7528Atomic\u7c7b&#xff08;\u63a8\u8350&#xff09;<br \/>\n    private AtomicInteger atomicCounter &#061; new AtomicInteger(0);<\/p>\n<p>    public void atomicIncrement() {<br \/>\n        atomicCounter.incrementAndGet();<br \/>\n    }<\/p>\n<p>    \/\/ \u89e3\u51b3\u65b9\u68483&#xff1a;\u4f7f\u7528ReentrantLock<br \/>\n    private int lockCounter &#061; 0;<br \/>\n    private ReentrantLock lock &#061; new ReentrantLock();<\/p>\n<p>    public void lockIncrement() {<br \/>\n        lock.lock();<br \/>\n        try {<br \/>\n            lockCounter&#043;&#043;;<br \/>\n        } finally {<br \/>\n            lock.unlock(); \/\/ \u5fc5\u987b\u5728finally\u4e2d\u91ca\u653e\u9501<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) throws InterruptedException {<br \/>\n        ThreadSafetyDemo demo &#061; new ThreadSafetyDemo();<br \/>\n        int threadCount &#061; 100;<br \/>\n        int incrementPerThread &#061; 1000;<\/p>\n<p>        \/\/ \u6d4b\u8bd5\u975e\u7ebf\u7a0b\u5b89\u5168\u7248\u672c<br \/>\n        testUnsafe(demo, threadCount, incrementPerThread);<\/p>\n<p>        \/\/ \u6d4b\u8bd5Atomic\u7248\u672c<br \/>\n        testAtomic(demo, threadCount, incrementPerThread);<br \/>\n    }<\/p>\n<p>    private static void testUnsafe(ThreadSafetyDemo demo, int threadCount, int incrementPerThread)<br \/>\n            throws InterruptedException {<br \/>\n        demo.unsafeCounter &#061; 0;<br \/>\n        Thread[] threads &#061; new Thread[threadCount];<\/p>\n<p>        long startTime &#061; System.currentTimeMillis();<br \/>\n        for (int i &#061; 0; i &lt; threadCount; i&#043;&#043;) {<br \/>\n            threads[i] &#061; new Thread(() -&gt; {<br \/>\n                for (int j &#061; 0; j &lt; incrementPerThread; j&#043;&#043;) {<br \/>\n                    demo.unsafeIncrement();<br \/>\n                }<br \/>\n            });<br \/>\n            threads[i].start();<br \/>\n        }<\/p>\n<p>        for (Thread thread : threads) {<br \/>\n            thread.join();<br \/>\n        }<\/p>\n<p>        long endTime &#061; System.currentTimeMillis();<br \/>\n        System.out.println(&#034;\u975e\u7ebf\u7a0b\u5b89\u5168 &#8211; \u7ed3\u679c: &#034; &#043; demo.unsafeCounter &#043;<br \/>\n                         &#034;, \u9884\u671f: &#034; &#043; (threadCount * incrementPerThread) &#043;<br \/>\n                         &#034;, \u8017\u65f6: &#034; &#043; (endTime &#8211; startTime) &#043; &#034;ms&#034;);<br \/>\n    }<\/p>\n<p>    private static void testAtomic(ThreadSafetyDemo demo, int threadCount, int incrementPerThread)<br \/>\n            throws InterruptedException {<br \/>\n        demo.atomicCounter.set(0);<br \/>\n        Thread[] threads &#061; new Thread[threadCount];<\/p>\n<p>        long startTime &#061; System.currentTimeMillis();<br \/>\n        for (int i &#061; 0; i &lt; threadCount; i&#043;&#043;) {<br \/>\n            threads[i] &#061; new Thread(() -&gt; {<br \/>\n                for (int j &#061; 0; j &lt; incrementPerThread; j&#043;&#043;) {<br \/>\n                    demo.atomicIncrement();<br \/>\n                }<br \/>\n            });<br \/>\n            threads[i].start();<br \/>\n        }<\/p>\n<p>        for (Thread thread : threads) {<br \/>\n            thread.join();<br \/>\n        }<\/p>\n<p>        long endTime &#061; System.currentTimeMillis();<br \/>\n        System.out.println(&#034;Atomic\u7c7b &#8211; \u7ed3\u679c: &#034; &#043; demo.atomicCounter.get() &#043;<br \/>\n                         &#034;, \u9884\u671f: &#034; &#043; (threadCount * incrementPerThread) &#043;<br \/>\n                         &#034;, \u8017\u65f6: &#034; &#043; (endTime &#8211; startTime) &#043; &#034;ms&#034;);<br \/>\n    }<br \/>\n}<\/p>\n<h3 id=\"toc-175136597ca5aec301bfa02f1b4c5963\">\u4e94\u3001\u5e76\u53d1\u5de5\u5177\u7c7b<\/h3>\n<\/p>\n<h4 id=\"toc-bc48278f3b380d5388ebec396cb1be63\">5.1 ThreadPoolExecutor\u7ebf\u7a0b\u6c60<\/h4>\n<\/p>\n<p>\u7ebf\u7a0b\u6c60\u80fd\u591f\u6709\u6548\u7ba1\u7406\u7ebf\u7a0b\u8d44\u6e90&#xff0c;\u63d0\u9ad8\u7a0b\u5e8f\u6027\u80fd\u3002<\/p>\n<p>import java.util.concurrent.*;<br \/>\nimport java.util.concurrent.atomic.AtomicInteger;<\/p>\n<p>public class ThreadPoolDemo {<br \/>\n    private static final AtomicInteger taskNumber &#061; new AtomicInteger(1);<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        \/\/ \u521b\u5efa\u7ebf\u7a0b\u6c60<br \/>\n        ThreadPoolExecutor executor &#061; new ThreadPoolExecutor(<br \/>\n            2,                          \/\/ \u6838\u5fc3\u7ebf\u7a0b\u6570<br \/>\n            4,                          \/\/ \u6700\u5927\u7ebf\u7a0b\u6570<br \/>\n            60L,                        \/\/ \u7a7a\u95f2\u7ebf\u7a0b\u5b58\u6d3b\u65f6\u95f4<br \/>\n            TimeUnit.SECONDS,           \/\/ \u65f6\u95f4\u5355\u4f4d<br \/>\n            new ArrayBlockingQueue&lt;&gt;(10), \/\/ \u4efb\u52a1\u961f\u5217<br \/>\n            Executors.defaultThreadFactory(), \/\/ \u7ebf\u7a0b\u5de5\u5382<br \/>\n            new ThreadPoolExecutor.CallerRunsPolicy() \/\/ \u62d2\u7edd\u7b56\u7565<br \/>\n        );<\/p>\n<p>        \/\/ \u63d0\u4ea4\u4efb\u52a1<br \/>\n        for (int i &#061; 0; i &lt; 15; i&#043;&#043;) {<br \/>\n            final int taskId &#061; taskNumber.getAndIncrement();<br \/>\n            executor.submit(() -&gt; {<br \/>\n                System.out.println(&#034;\u4efb\u52a1&#034; &#043; taskId &#043; &#034;\u5f00\u59cb\u6267\u884c &#8211; &#034; &#043;<br \/>\n                    Thread.currentThread().getName());<br \/>\n                try {<br \/>\n                    Thread.sleep(1000); \/\/ \u6a21\u62df\u4efb\u52a1\u6267\u884c<br \/>\n                } catch (InterruptedException e) {<br \/>\n                    e.printStackTrace();<br \/>\n                }<br \/>\n                System.out.println(&#034;\u4efb\u52a1&#034; &#043; taskId &#043; &#034;\u6267\u884c\u5b8c\u6210&#034;);<br \/>\n                return &#034;\u4efb\u52a1&#034; &#043; taskId &#043; &#034;\u7684\u7ed3\u679c&#034;;<br \/>\n            });<br \/>\n        }<\/p>\n<p>        \/\/ \u5173\u95ed\u7ebf\u7a0b\u6c60<br \/>\n        executor.shutdown();<br \/>\n        try {<br \/>\n            \/\/ \u7b49\u5f85\u6240\u6709\u4efb\u52a1\u5b8c\u6210<br \/>\n            if (!executor.awaitTermination(60, TimeUnit.SECONDS)) {<br \/>\n                executor.shutdownNow();<br \/>\n            }<br \/>\n        } catch (InterruptedException e) {<br \/>\n            executor.shutdownNow();<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<h4 id=\"toc-bf7007d7c10151d0d1b28d0abe49d0c1\">5.2 CountDownLatch\u5012\u8ba1\u65f6\u95e8\u6813<\/h4>\n<\/p>\n<p>CountDownLatch\u7528\u4e8e\u534f\u8c03\u591a\u4e2a\u7ebf\u7a0b\u4e4b\u95f4\u7684\u6267\u884c\u987a\u5e8f\u3002<\/p>\n<p>import java.util.concurrent.*;<br \/>\nimport java.util.concurrent.atomic.AtomicInteger;<\/p>\n<p>public class CountDownLatchDemo {<br \/>\n    public static void main(String[] args) throws InterruptedException {<br \/>\n        final int THREAD_COUNT &#061; 5;<br \/>\n        CountDownLatch startLatch &#061; new CountDownLatch(1);  \/\/ \u5f00\u59cb\u4fe1\u53f7<br \/>\n        CountDownLatch endLatch &#061; new CountDownLatch(THREAD_COUNT); \/\/ \u7ed3\u675f\u4fe1\u53f7<br \/>\n        AtomicInteger resultSum &#061; new AtomicInteger(0);<\/p>\n<p>        \/\/ \u521b\u5efa\u5e76\u542f\u52a8\u5de5\u4f5c\u7ebf\u7a0b<br \/>\n        for (int i &#061; 1; i &lt;&#061; THREAD_COUNT; i&#043;&#043;) {<br \/>\n            final int threadId &#061; i;<br \/>\n            new Thread(() -&gt; {<br \/>\n                try {<br \/>\n                    System.out.println(&#034;\u7ebf\u7a0b&#034; &#043; threadId &#043; &#034;\u51c6\u5907\u5c31\u7eea&#xff0c;\u7b49\u5f85\u5f00\u59cb\u4fe1\u53f7&#8230;&#034;);<br \/>\n                    startLatch.await(); \/\/ \u7b49\u5f85\u5f00\u59cb\u4fe1\u53f7<\/p>\n<p>                    System.out.println(&#034;\u7ebf\u7a0b&#034; &#043; threadId &#043; &#034;\u5f00\u59cb\u6267\u884c\u4efb\u52a1&#034;);<br \/>\n                    int result &#061; threadId * threadId; \/\/ \u6a21\u62df\u8ba1\u7b97\u4efb\u52a1<br \/>\n                    Thread.sleep(1000); \/\/ \u6a21\u62df\u8017\u65f6\u64cd\u4f5c<\/p>\n<p>                    resultSum.addAndGet(result);<br \/>\n                    System.out.println(&#034;\u7ebf\u7a0b&#034; &#043; threadId &#043; &#034;\u6267\u884c\u5b8c\u6210&#xff0c;\u7ed3\u679c: &#034; &#043; result);<\/p>\n<p>                } catch (InterruptedException e) {<br \/>\n                    e.printStackTrace();<br \/>\n                } finally {<br \/>\n                    endLatch.countDown(); \/\/ \u5b8c\u6210\u540e\u5012\u8ba1\u65f6<br \/>\n                }<br \/>\n            }).start();<br \/>\n        }<\/p>\n<p>        \/\/ \u4e3b\u7ebf\u7a0b\u7b49\u5f85\u6240\u6709\u7ebf\u7a0b\u51c6\u5907\u5c31\u7eea<br \/>\n        Thread.sleep(100);<br \/>\n        System.out.println(&#034;\u4e3b\u7ebf\u7a0b&#xff1a;\u6240\u6709\u5de5\u4f5c\u7ebf\u7a0b\u51c6\u5907\u5c31\u7eea&#xff0c;\u53d1\u9001\u5f00\u59cb\u4fe1\u53f7&#xff01;&#034;);<br \/>\n        startLatch.countDown(); \/\/ \u53d1\u9001\u5f00\u59cb\u4fe1\u53f7<\/p>\n<p>        \/\/ \u7b49\u5f85\u6240\u6709\u5de5\u4f5c\u7ebf\u7a0b\u5b8c\u6210<br \/>\n        endLatch.await();<br \/>\n        System.out.println(&#034;\u4e3b\u7ebf\u7a0b&#xff1a;\u6240\u6709\u4efb\u52a1\u6267\u884c\u5b8c\u6210&#xff0c;\u603b\u548c: &#034; &#043; resultSum.get());<br \/>\n    }<br \/>\n}<\/p>\n<h4 id=\"toc-66b9f19870a34a2cc6a4d7b8628089ef\">5.3 \u5176\u4ed6\u5e38\u7528\u5de5\u5177\u7c7b\u7b80\u4ecb<\/h4>\n<\/p>\n<ul>\n<li>Semaphore&#xff08;\u4fe1\u53f7\u91cf&#xff09; &#xff1a;\u63a7\u5236\u540c\u65f6\u8bbf\u95ee\u7279\u5b9a\u8d44\u6e90\u7684\u7ebf\u7a0b\u6570\u91cf<\/li>\n<li>CyclicBarrier&#xff08;\u5faa\u73af\u6805\u680f&#xff09; &#xff1a;\u8ba9\u4e00\u7ec4\u7ebf\u7a0b\u5230\u8fbe\u4e00\u4e2a\u5c4f\u969c\u65f6\u88ab\u963b\u585e&#xff0c;\u76f4\u5230\u6700\u540e\u4e00\u4e2a\u7ebf\u7a0b\u5230\u8fbe\u5c4f\u969c\u65f6&#xff0c;\u6240\u6709\u88ab\u5c4f\u969c\u62e6\u622a\u7684\u7ebf\u7a0b\u624d\u4f1a\u7ee7\u7eed\u6267\u884c<\/li>\n<li>ConcurrentHashMap&#xff1a;\u7ebf\u7a0b\u5b89\u5168\u7684HashMap\u5b9e\u73b0<\/li>\n<li>BlockingQueue&#xff1a;\u963b\u585e\u961f\u5217&#xff0c;\u652f\u6301\u7ebf\u7a0b\u5b89\u5168\u7684\u751f\u4ea7-\u6d88\u8d39\u6a21\u5f0f<\/li>\n<\/ul>\n<h3 id=\"toc-5b7314fdaaee7eccab8f99b9a9077366\">\u516d\u3001\u5b9e\u8df5\u5efa\u8bae<\/h3>\n<\/p>\n<h4 id=\"toc-862fa029d3b0e3c10e5cb1e440990cfe\">6.1 \u5e76\u53d1\u7f16\u7a0b\u5e38\u89c1\u95ee\u9898\u53ca\u907f\u5751\u6307\u5357<\/h4>\n<\/p>\n<h5 id=\"toc-2971b81c76a9536c2e2cce5120567803\">6.1.1 \u6b7b\u9501\u95ee\u9898<\/h5>\n<p>public class DeadlockDemo {<br \/>\n    private static final Object lock1 &#061; new Object();<br \/>\n    private static final Object lock2 &#061; new Object();<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        Thread thread1 &#061; new Thread(() -&gt; {<br \/>\n            synchronized (lock1) {<br \/>\n                System.out.println(&#034;\u7ebf\u7a0b1\u83b7\u53d6lock1&#034;);<br \/>\n                try { Thread.sleep(100); } catch (InterruptedException e) {}<br \/>\n                System.out.println(&#034;\u7ebf\u7a0b1\u7b49\u5f85lock2&#034;);<br \/>\n                synchronized (lock2) {<br \/>\n                    System.out.println(&#034;\u7ebf\u7a0b1\u83b7\u53d6lock2&#034;);<br \/>\n                }<br \/>\n            }<br \/>\n        });<\/p>\n<p>        Thread thread2 &#061; new Thread(() -&gt; {<br \/>\n            synchronized (lock2) {<br \/>\n                System.out.println(&#034;\u7ebf\u7a0b2\u83b7\u53d6lock2&#034;);<br \/>\n                try { Thread.sleep(100); } catch (InterruptedException e) {}<br \/>\n                System.out.println(&#034;\u7ebf\u7a0b2\u7b49\u5f85lock1&#034;);<br \/>\n                synchronized (lock1) {<br \/>\n                    System.out.println(&#034;\u7ebf\u7a0b2\u83b7\u53d6lock1&#034;);<br \/>\n                }<br \/>\n            }<br \/>\n        });<\/p>\n<p>        thread1.start();<br \/>\n        thread2.start();<br \/>\n        \/\/ \u53ef\u80fd\u4ea7\u751f\u6b7b\u9501<br \/>\n    }<br \/>\n}<\/p>\n<p>\u907f\u5751\u5efa\u8bae&#xff1a;<\/p>\n<\/p>\n<ul>\n<li>\u907f\u514d\u5d4c\u5957\u9501<\/li>\n<li>\u6309\u7167\u56fa\u5b9a\u987a\u5e8f\u83b7\u53d6\u9501<\/li>\n<li>\u8bbe\u7f6e\u9501\u8d85\u65f6\u65f6\u95f4<\/li>\n<li>\u4f7f\u7528tryLock()\u66ff\u4ee3lock()<\/li>\n<\/ul>\n<h5 id=\"toc-b075032f11681b45786247fc715b6f2d\">6.1.2 \u8d44\u6e90\u6cc4\u6f0f<\/h5>\n<p>\/\/ \u9519\u8bef\u793a\u4f8b&#xff1a;\u7ebf\u7a0b\u6c60\u672a\u6b63\u786e\u5173\u95ed<br \/>\npublic class ResourceLeakDemo {<br \/>\n    public static void wrongExample() {<br \/>\n        ThreadPoolExecutor executor &#061; (ThreadPoolExecutor) Executors.newFixedThreadPool(10);<br \/>\n        executor.submit(() -&gt; System.out.println(&#034;\u4efb\u52a1\u6267\u884c&#034;));<br \/>\n        \/\/ \u5fd8\u8bb0\u8c03\u7528shutdown()&#xff0c;\u5bfc\u81f4\u7ebf\u7a0b\u6c60\u65e0\u6cd5\u5173\u95ed<br \/>\n    }<\/p>\n<p>    \/\/ \u6b63\u786e\u793a\u4f8b<br \/>\n    public static void correctExample() {<br \/>\n        ThreadPoolExecutor executor &#061; (ThreadPoolExecutor) Executors.newFixedThreadPool(10);<br \/>\n        try {<br \/>\n            executor.submit(() -&gt; System.out.println(&#034;\u4efb\u52a1\u6267\u884c&#034;));<br \/>\n        } finally {<br \/>\n            executor.shutdown(); \/\/ \u786e\u4fdd\u7ebf\u7a0b\u6c60\u88ab\u5173\u95ed<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<h4 id=\"toc-5a9329102308ecabfb28cfd3277c1bd2\">6.2 \u6027\u80fd\u4f18\u5316\u65b9\u5411<\/h4>\n<\/p>\n<li>\u5408\u7406\u4f7f\u7528\u7ebf\u7a0b\u6c60&#xff1a;\u6839\u636e\u4efb\u52a1\u7c7b\u578b\u9009\u62e9\u5408\u9002\u7684\u7ebf\u7a0b\u6c60\u53c2\u6570<\/li>\n<li>\u51cf\u5c11\u9501\u7c92\u5ea6&#xff1a;\u4f7f\u7528\u7ec6\u7c92\u5ea6\u9501\u4ee3\u66ff\u7c97\u7c92\u5ea6\u9501<\/li>\n<li>\u4f7f\u7528\u65e0\u9501\u7f16\u7a0b&#xff1a;\u4f18\u5148\u4f7f\u7528Atomic\u7c7b\u548c\u5e76\u53d1\u96c6\u5408<\/li>\n<li>\u907f\u514d\u4e0a\u4e0b\u6587\u5207\u6362&#xff1a;\u51cf\u5c11\u7ebf\u7a0b\u521b\u5efa\u548c\u9500\u6bc1\u5f00\u9500<\/li>\n<li>\u5408\u7406\u8bbe\u7f6e\u7ebf\u7a0b\u6570\u91cf&#xff1a;\u901a\u5e38\u8bbe\u7f6e\u4e3aCPU\u6838\u5fc3\u6570\u76841-2\u500d<\/li>\n<p>import java.util.concurrent.*;<br \/>\nimport java.util.concurrent.atomic.AtomicLong;<\/p>\n<p>public class PerformanceOptimizationDemo {<br \/>\n    \/\/ \u6027\u80fd\u5bf9\u6bd4&#xff1a;\u540c\u6b65\u65b9\u5f0f vs \u65e0\u9501\u65b9\u5f0f<br \/>\n    private long syncCounter &#061; 0;<br \/>\n    private AtomicLong atomicCounter &#061; new AtomicLong(0);<\/p>\n<p>    \/\/ \u540c\u6b65\u65b9\u5f0f<br \/>\n    public synchronized void syncIncrement() {<br \/>\n        syncCounter&#043;&#043;;<br \/>\n    }<\/p>\n<p>    \/\/ \u65e0\u9501\u65b9\u5f0f<br \/>\n    public void atomicIncrement() {<br \/>\n        atomicCounter.incrementAndGet();<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) throws InterruptedException {<br \/>\n        PerformanceOptimizationDemo demo &#061; new PerformanceOptimizationDemo();<br \/>\n        int threadCount &#061; 10;<br \/>\n        int operations &#061; 1000000;<\/p>\n<p>        \/\/ \u6d4b\u8bd5synchronized\u6027\u80fd<br \/>\n        long syncStart &#061; System.currentTimeMillis();<br \/>\n        testSyncMethod(demo, threadCount, operations);<br \/>\n        long syncEnd &#061; System.currentTimeMillis();<\/p>\n<p>        \/\/ \u6d4b\u8bd5Atomic\u6027\u80fd<br \/>\n        long atomicStart &#061; System.currentTimeMillis();<br \/>\n        testAtomicMethod(demo, threadCount, operations);<br \/>\n        long atomicEnd &#061; System.currentTimeMillis();<\/p>\n<p>        System.out.println(&#034;synchronized\u8017\u65f6: &#034; &#043; (syncEnd &#8211; syncStart) &#043; &#034;ms&#034;);<br \/>\n        System.out.println(&#034;Atomic\u8017\u65f6: &#034; &#043; (atomicEnd &#8211; atomicStart) &#043; &#034;ms&#034;);<br \/>\n    }<\/p>\n<p>    private static void testSyncMethod(PerformanceOptimizationDemo demo,<br \/>\n                                      int threadCount, int operations)<br \/>\n            throws InterruptedException {<br \/>\n        demo.syncCounter &#061; 0;<br \/>\n        CountDownLatch latch &#061; new CountDownLatch(threadCount);<\/p>\n<p>        for (int i &#061; 0; i &lt; threadCount; i&#043;&#043;) {<br \/>\n            new Thread(() -&gt; {<br \/>\n                for (int j &#061; 0; j &lt; operations; j&#043;&#043;) {<br \/>\n                    demo.syncIncrement();<br \/>\n                }<br \/>\n                latch.countDown();<br \/>\n            }).start();<br \/>\n        }<\/p>\n<p>        latch.await();<br \/>\n    }<\/p>\n<p>    private static void testAtomicMethod(PerformanceOptimizationDemo demo,<br \/>\n                                        int threadCount, int operations)<br \/>\n            throws InterruptedException {<br \/>\n        demo.atomicCounter.set(0);<br \/>\n        CountDownLatch latch &#061; new CountDownLatch(threadCount);<\/p>\n<p>        for (int i &#061; 0; i &lt; threadCount; i&#043;&#043;) {<br \/>\n            new Thread(() -&gt; {<br \/>\n                for (int j &#061; 0; j &lt; operations; j&#043;&#043;) {<br \/>\n                    demo.atomicIncrement();<br \/>\n                }<br \/>\n                latch.countDown();<br \/>\n            }).start();<br \/>\n        }<\/p>\n<p>        latch.await();<br \/>\n    }<br \/>\n}<\/p>\n<h3 id=\"toc-f872ff4ac51079f3d906fb2e4c323235\">\u4e03\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p>Java\u5e76\u53d1\u7f16\u7a0b\u662f\u6784\u5efa\u9ad8\u6027\u80fd\u5e94\u7528\u7684\u91cd\u8981\u6280\u672f&#xff0c;\u638c\u63e1\u5176\u6838\u5fc3\u6982\u5ff5\u548c\u5b9e\u8df5\u6280\u5de7\u5bf9\u5f00\u53d1\u8005\u81f3\u5173\u91cd\u8981\u3002\u672c\u6587\u4ece\u5e76\u53d1\u7f16\u7a0b\u7684\u57fa\u7840\u6982\u5ff5\u5165\u624b&#xff0c;\u8be6\u7ec6\u4ecb\u7ecd\u4e86Java\u4e2d\u7684\u7ebf\u7a0b\u521b\u5efa\u3001\u540c\u6b65\u673a\u5236\u3001\u5e76\u53d1\u5de5\u5177\u7c7b\u7b49\u6838\u5fc3\u5185\u5bb9&#xff0c;\u5e76\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u4ee3\u7801\u793a\u4f8b\u548c\u5b9e\u8df5\u5efa\u8bae\u3002<\/p>\n<\/p>\n<p>\u6838\u5fc3\u77e5\u8bc6\u70b9\u56de\u987e&#xff1a;<\/p>\n<\/p>\n<li>\u8fdb\u7a0b\u4e0e\u7ebf\u7a0b&#xff1a;\u7406\u89e3\u8fdb\u7a0b\u548c\u7ebf\u7a0b\u7684\u533a\u522b&#xff0c;\u638c\u63e1\u5e76\u53d1\u4e0e\u5e76\u884c\u7684\u6982\u5ff5<\/li>\n<li>\u7ebf\u7a0b\u521b\u5efa&#xff1a;\u4f18\u5148\u4f7f\u7528Runnable\u63a5\u53e3&#xff0c;\u907f\u514d\u7ee7\u627fThread\u7c7b\u7684\u5355\u7ee7\u627f\u9650\u5236<\/li>\n<li>\u540c\u6b65\u673a\u5236&#xff1a;\u5408\u7406\u4f7f\u7528synchronized\u548cvolatile&#xff0c;\u7406\u89e3\u5176\u5e95\u5c42\u539f\u7406<\/li>\n<li>\u7ebf\u7a0b\u5b89\u5168&#xff1a;\u8bc6\u522b\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898&#xff0c;\u9009\u62e9\u5408\u9002\u7684\u89e3\u51b3\u65b9\u6848&#xff08;Atomic\u7c7b\u3001Lock\u7b49&#xff09;<\/li>\n<li>\u5e76\u53d1\u5de5\u5177&#xff1a;\u719f\u7ec3\u4f7f\u7528\u7ebf\u7a0b\u6c60\u3001CountDownLatch\u7b49\u5e76\u53d1\u5de5\u5177\u63d0\u9ad8\u7a0b\u5e8f\u6027\u80fd<\/li>\n<li>\u6027\u80fd\u4f18\u5316&#xff1a;\u901a\u8fc7\u51cf\u5c11\u9501\u7c92\u5ea6\u3001\u4f7f\u7528\u65e0\u9501\u7f16\u7a0b\u7b49\u65b9\u5f0f\u4f18\u5316\u5e76\u53d1\u6027\u80fd<\/li>\n<p>Java\u5e76\u53d1\u7f16\u7a0b\u7684\u53d1\u5c55\u5c55\u671b&#xff1a;<\/p>\n<\/p>\n<p>\u968f\u7740Java\u7248\u672c\u7684\u4e0d\u65ad\u66f4\u65b0&#xff0c;\u5e76\u53d1\u7f16\u7a0bAPI\u4e5f\u5728\u6301\u7eed\u4f18\u5316\u3002Java 8\u5f15\u5165\u7684CompletableFuture\u5927\u5927\u7b80\u5316\u4e86\u5f02\u6b65\u7f16\u7a0b&#xff0c;Java 9\u7684\u54cd\u5e94\u5f0f\u7f16\u7a0b\u652f\u6301\u4e3a\u5e76\u53d1\u7f16\u7a0b\u5e26\u6765\u4e86\u65b0\u7684\u53ef\u80fd\u6027\u3002\u672a\u6765&#xff0c;Java\u5e76\u53d1\u7f16\u7a0b\u5c06\u66f4\u52a0\u6ce8\u91cd\u6027\u80fd\u4f18\u5316\u3001\u6613\u7528\u6027\u548c\u53ef\u7ef4\u62a4\u6027&#xff0c;\u5f00\u53d1\u8005\u9700\u8981\u6301\u7eed\u5b66\u4e60\u548c\u638c\u63e1\u65b0\u7684\u5e76\u53d1\u7f16\u7a0b\u6280\u672f\u3002<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u5f15\u8a00 \u5728\u5f53\u4eca\u8ba1\u7b97\u673a\u786c\u4ef6\u98de\u901f\u53d1\u5c55\u7684\u80cc\u666f\u4e0b&#xff0c;\u591a\u6838\u5904\u7406\u5668\u5df2\u7ecf\u6210\u4e3a\u6807\u51c6\u914d\u7f6e\u3002\u5982\u4f55\u5145\u5206\u5229\u7528\u591a\u6838CPU\u7684\u8ba1\u7b97\u80fd\u529b&#xff0c;\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u54cd\u5e94\u901f\u5ea6&#xff0c;\u6210\u4e3a\u6bcf\u4e2aJava\u5f00\u53d1\u8005\u5fc5\u987b\u638c\u63e1\u7684\u6838\u5fc3\u6280\u80fd\u3002\u5e76\u53d1\u7f16\u7a0b\u4f5c\u4e3a\u63d0\u5347\u7a0b\u5e8f\u6027\u80fd\u7684\u91cd\u8981\u624b\u6bb5&#xff0c;\u5728Java\u751f\u6001\u7cfb\u7edf\u4e2d\u5360\u636e\u7740\u91cd\u8981\u5730\u4f4d\u3002 Java\u4ece\u8bde\u751f\u4e4b\u521d\u5c31\u5c06\u591a\u7ebf\u7a0b\u652f\u6301\u4f5c\u4e3a\u6838\u5fc3\u7279\u6027\u4e4b\u4e00&#xff0c;\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5e76\u53d1\u7f16\u7a0bAPI\u548c\u5de5\u5177\u7c7b\u3002\u4ece\u57fa\u7840\u7684Thread\u7c7b\u5230\u9ad8\u7ea7\u7684\u5e76\u53d1\u96c6\u5408&#xff0c;\u4ece\u7b80\u5355\u7684\u540c\u6b65\u673a\u5236\u5230<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,190],"topic":[],"class_list":["post-71142","post","type-post","status-publish","format-standard","hentry","category-server","tag-java","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java\u5e76\u53d1\u7f16\u7a0b\u57fa\u7840\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/71142.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java\u5e76\u53d1\u7f16\u7a0b\u57fa\u7840\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e00\u3001\u5f15\u8a00 \u5728\u5f53\u4eca\u8ba1\u7b97\u673a\u786c\u4ef6\u98de\u901f\u53d1\u5c55\u7684\u80cc\u666f\u4e0b&#xff0c;\u591a\u6838\u5904\u7406\u5668\u5df2\u7ecf\u6210\u4e3a\u6807\u51c6\u914d\u7f6e\u3002\u5982\u4f55\u5145\u5206\u5229\u7528\u591a\u6838CPU\u7684\u8ba1\u7b97\u80fd\u529b&#xff0c;\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u54cd\u5e94\u901f\u5ea6&#xff0c;\u6210\u4e3a\u6bcf\u4e2aJava\u5f00\u53d1\u8005\u5fc5\u987b\u638c\u63e1\u7684\u6838\u5fc3\u6280\u80fd\u3002\u5e76\u53d1\u7f16\u7a0b\u4f5c\u4e3a\u63d0\u5347\u7a0b\u5e8f\u6027\u80fd\u7684\u91cd\u8981\u624b\u6bb5&#xff0c;\u5728Java\u751f\u6001\u7cfb\u7edf\u4e2d\u5360\u636e\u7740\u91cd\u8981\u5730\u4f4d\u3002 Java\u4ece\u8bde\u751f\u4e4b\u521d\u5c31\u5c06\u591a\u7ebf\u7a0b\u652f\u6301\u4f5c\u4e3a\u6838\u5fc3\u7279\u6027\u4e4b\u4e00&#xff0c;\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5e76\u53d1\u7f16\u7a0bAPI\u548c\u5de5\u5177\u7c7b\u3002\u4ece\u57fa\u7840\u7684Thread\u7c7b\u5230\u9ad8\u7ea7\u7684\u5e76\u53d1\u96c6\u5408&#xff0c;\u4ece\u7b80\u5355\u7684\u540c\u6b65\u673a\u5236\u5230\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/71142.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-03T01:24:41+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/71142.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/71142.html\",\"name\":\"Java\u5e76\u53d1\u7f16\u7a0b\u57fa\u7840\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-03T01:24:41+00:00\",\"dateModified\":\"2026-02-03T01:24:41+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/71142.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/71142.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/71142.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\u5e76\u53d1\u7f16\u7a0b\u57fa\u7840\u89e3\u6790\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java\u5e76\u53d1\u7f16\u7a0b\u57fa\u7840\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/71142.html","og_locale":"zh_CN","og_type":"article","og_title":"Java\u5e76\u53d1\u7f16\u7a0b\u57fa\u7840\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e00\u3001\u5f15\u8a00 \u5728\u5f53\u4eca\u8ba1\u7b97\u673a\u786c\u4ef6\u98de\u901f\u53d1\u5c55\u7684\u80cc\u666f\u4e0b&#xff0c;\u591a\u6838\u5904\u7406\u5668\u5df2\u7ecf\u6210\u4e3a\u6807\u51c6\u914d\u7f6e\u3002\u5982\u4f55\u5145\u5206\u5229\u7528\u591a\u6838CPU\u7684\u8ba1\u7b97\u80fd\u529b&#xff0c;\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u54cd\u5e94\u901f\u5ea6&#xff0c;\u6210\u4e3a\u6bcf\u4e2aJava\u5f00\u53d1\u8005\u5fc5\u987b\u638c\u63e1\u7684\u6838\u5fc3\u6280\u80fd\u3002\u5e76\u53d1\u7f16\u7a0b\u4f5c\u4e3a\u63d0\u5347\u7a0b\u5e8f\u6027\u80fd\u7684\u91cd\u8981\u624b\u6bb5&#xff0c;\u5728Java\u751f\u6001\u7cfb\u7edf\u4e2d\u5360\u636e\u7740\u91cd\u8981\u5730\u4f4d\u3002 Java\u4ece\u8bde\u751f\u4e4b\u521d\u5c31\u5c06\u591a\u7ebf\u7a0b\u652f\u6301\u4f5c\u4e3a\u6838\u5fc3\u7279\u6027\u4e4b\u4e00&#xff0c;\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5e76\u53d1\u7f16\u7a0bAPI\u548c\u5de5\u5177\u7c7b\u3002\u4ece\u57fa\u7840\u7684Thread\u7c7b\u5230\u9ad8\u7ea7\u7684\u5e76\u53d1\u96c6\u5408&#xff0c;\u4ece\u7b80\u5355\u7684\u540c\u6b65\u673a\u5236\u5230","og_url":"https:\/\/www.wsisp.com\/helps\/71142.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-03T01:24:41+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/71142.html","url":"https:\/\/www.wsisp.com\/helps\/71142.html","name":"Java\u5e76\u53d1\u7f16\u7a0b\u57fa\u7840\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-03T01:24:41+00:00","dateModified":"2026-02-03T01:24:41+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/71142.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/71142.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/71142.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Java\u5e76\u53d1\u7f16\u7a0b\u57fa\u7840\u89e3\u6790"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/71142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=71142"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/71142\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=71142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=71142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=71142"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=71142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}