原创转载请注明出处:http://agilestyle.iteye.com/blog/2344621
getRegisteredParties()
getRegisteredParties()作用是获得注册的parties数量
register()
register()作用是动态添加一个parties值
PhaserTest6.java
package org.fool.java.concurrent.phaser; import java.util.concurrent.Phaser; public class PhaserTest6 { public static void main(String[] args) { Phaser phaser = new Phaser(5); System.out.println(phaser.getRegisteredParties()); phaser.register(); System.out.println(phaser.getRegisteredParties()); phaser.register(); System.out.println(phaser.getRegisteredParties()); phaser.register(); System.out.println(phaser.getRegisteredParties()); phaser.register(); System.out.println(phaser.getRegisteredParties()); phaser.register(); System.out.println(phaser.getRegisteredParties()); } }
Run
bulkRegister(int parties)
bulkRegister(int parties)作用是批量增加parties的数量
PhaserTest10.java
package org.fool.java.concurrent.phaser; import java.util.concurrent.Phaser; public class PhaserTest10 { public static void main(String[] args) { Phaser phaser = new Phaser(5); System.out.println(phaser.getRegisteredParties()); phaser.bulkRegister(10); System.out.println(phaser.getRegisteredParties()); phaser.bulkRegister(10); System.out.println(phaser.getRegisteredParties()); phaser.bulkRegister(10); System.out.println(phaser.getRegisteredParties()); phaser.bulkRegister(10); System.out.println(phaser.getRegisteredParties()); } }
Run
getArrivedParties()
getArrivedParties()作用是获得已经被使用的parties的个数
getUnarrivedParties()
getUnarrivedParties()作用是获得未被使用的parties的个数
PhaserTest7.java
package org.fool.java.concurrent.phaser; import java.util.concurrent.Phaser; public class PhaserTest7 { public static class MyThread implements Runnable { private Phaser phaser; public MyThread(Phaser phaser) { this.phaser = phaser; } @Override public void run() { System.out.println(Thread.currentThread().getName() + " begin " + System.currentTimeMillis()); phaser.arriveAndAwaitAdvance(); System.out.println(Thread.currentThread().getName() + " end " + System.currentTimeMillis()); } } public static void main(String[] args) { try { Phaser phaser = new Phaser(10); for (int i = 0; i < 8; i++) { Thread thread = new Thread(new MyThread(phaser)); thread.setName("Thread " + (i + 1)); thread.start(); } Thread.sleep(3000); System.out.println(phaser.getArrivedParties()); System.out.println(phaser.getUnarrivedParties()); } catch (InterruptedException e) { e.printStackTrace(); } } }
Run
Reference
Java并发编程核心方法与框架
相关推荐
backport-util-concurrent-3.1.jar 和 geronimo-stax-api_1.0_spec-1.0.1.jar 复制到 MyEclipse 6.5\eclipse\plugins\Axis2_Codegen_Wizard_1.3.0\lib 文件夹下。 (3).注册此 jar 包: 修改MyEclipse 6.5\eclipse...
JavaEE源代码 concurrent-1.3.2JavaEE源代码 concurrent-1.3.2JavaEE源代码 concurrent-1.3.2JavaEE源代码 concurrent-1.3.2JavaEE源代码 concurrent-1.3.2JavaEE源代码 concurrent-1.3.2JavaEE源代码 concurrent-...
在Eclipse3.5用Axis2中创建wsdl文件时,在最后一步出现如下错误: An error ocCurred while ...解决用到的jar包,两个jar包在backport-util-concurrent-3.1.jar和geronimo-stax-api_1.0_spec-1.0.1.jar.zip的压缩文件中
- copy %AXIS2_HOME%\lib\backport-util-concurrent-3.1.jar 到%ECLIPSE_HOME%\plugins\Axis2_Codegen_Wizard_1.3.0\lib - 注册此 jar 包: 編輯 %ECLIPSE_HOME%\plugins\Axis2_Codegen_Wizard_1.3.0\plugin.xml , ...
concurrent-1.3.4.jar
官方版本,亲测可用
《并发编程库 concurrent-1.3.4-sources.jar 深度解析》 在Java编程领域,"concurrent"一词通常与多线程和并发处理相关,它指的是能够同时执行多个任务的能力。这里提到的`concurrent-1.3.4-sources.jar`是一个特定...
Concurrent-Utils Utilities for Java concurrent library. This is a library contains some useful and smart utility class for Java concurrent library. Shelly, HermesEventBus and AndroidDataStorage are ...
concurrent-1.3.2.ja
《深入解析Atlassian Util Concurrent库:0.0.12版本》 在IT行业中,高效且可靠的并发处理是系统性能优化的关键因素之一。Atlassian公司,以其强大的协作工具如Jira、Confluence等闻名,也提供了许多开源工具来支持...
- 在3.1版本中,backport-util-concurrent引入了Phaser,这是一个可重用的同步帮助器类,支持多个参与者之间的有界同步,类似于CyclicBarrier和CountDownLatch,但更灵活。Phaser可以自动调整参与者的数量,并且在...
backport-util-concurrent-1.0.jar,
patterns-for-concurrent-and-networked-objects