Java Code Examples for java.util.concurrent.Phaser#getPhase()

The following examples show how to use java.util.concurrent.Phaser#getPhase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Basic.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void checkTerminated(final Phaser phaser) {
    check(phaser.isTerminated());
    int unarriverParties = phaser.getUnarrivedParties();
    int registeredParties = phaser.getRegisteredParties();
    int phase = phaser.getPhase();
    check(phase < 0);
    equal(phase, phaser.arrive());
    equal(phase, phaser.arriveAndDeregister());
    equal(phase, phaser.arriveAndAwaitAdvance());
    equal(phase, phaser.bulkRegister(10));
    equal(phase, phaser.register());
    try {
        equal(phase, phaser.awaitAdvanceInterruptibly(0));
        equal(phase, phaser.awaitAdvanceInterruptibly(0, 10, SECONDS));
    } catch (Exception ie) {
        unexpected(ie);
    }
    equal(phaser.getUnarrivedParties(), unarriverParties);
    equal(phaser.getRegisteredParties(), registeredParties);
}
 
Example 2
Source File: Basic.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void checkTerminated(final Phaser phaser) {
    check(phaser.isTerminated());
    int unarriverParties = phaser.getUnarrivedParties();
    int registeredParties = phaser.getRegisteredParties();
    int phase = phaser.getPhase();
    check(phase < 0);
    equal(phase, phaser.arrive());
    equal(phase, phaser.arriveAndDeregister());
    equal(phase, phaser.arriveAndAwaitAdvance());
    equal(phase, phaser.bulkRegister(10));
    equal(phase, phaser.register());
    try {
        equal(phase, phaser.awaitAdvanceInterruptibly(0));
        equal(phase, phaser.awaitAdvanceInterruptibly(0, 10, SECONDS));
    } catch (Exception ie) {
        unexpected(ie);
    }
    equal(phaser.getUnarrivedParties(), unarriverParties);
    equal(phaser.getRegisteredParties(), registeredParties);
}
 
Example 3
Source File: Basic.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void checkTerminated(final Phaser phaser) {
    check(phaser.isTerminated());
    int unarriverParties = phaser.getUnarrivedParties();
    int registeredParties = phaser.getRegisteredParties();
    int phase = phaser.getPhase();
    check(phase < 0);
    equal(phase, phaser.arrive());
    equal(phase, phaser.arriveAndDeregister());
    equal(phase, phaser.arriveAndAwaitAdvance());
    equal(phase, phaser.bulkRegister(10));
    equal(phase, phaser.register());
    try {
        equal(phase, phaser.awaitAdvanceInterruptibly(0));
        equal(phase, phaser.awaitAdvanceInterruptibly(0, 10, SECONDS));
    } catch (Exception ie) {
        unexpected(ie);
    }
    equal(phaser.getUnarrivedParties(), unarriverParties);
    equal(phaser.getRegisteredParties(), registeredParties);
}
 
Example 4
Source File: Basic.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void checkTerminated(final Phaser phaser) {
    check(phaser.isTerminated());
    int unarriverParties = phaser.getUnarrivedParties();
    int registeredParties = phaser.getRegisteredParties();
    int phase = phaser.getPhase();
    check(phase < 0);
    equal(phase, phaser.arrive());
    equal(phase, phaser.arriveAndDeregister());
    equal(phase, phaser.arriveAndAwaitAdvance());
    equal(phase, phaser.bulkRegister(10));
    equal(phase, phaser.register());
    try {
        equal(phase, phaser.awaitAdvanceInterruptibly(0));
        equal(phase, phaser.awaitAdvanceInterruptibly(0, 10, SECONDS));
    } catch (Exception ie) {
        unexpected(ie);
    }
    equal(phaser.getUnarrivedParties(), unarriverParties);
    equal(phaser.getRegisteredParties(), registeredParties);
}
 
Example 5
Source File: Basic.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void checkTerminated(final Phaser phaser) {
    check(phaser.isTerminated());
    int unarriverParties = phaser.getUnarrivedParties();
    int registeredParties = phaser.getRegisteredParties();
    int phase = phaser.getPhase();
    check(phase < 0);
    equal(phase, phaser.arrive());
    equal(phase, phaser.arriveAndDeregister());
    equal(phase, phaser.arriveAndAwaitAdvance());
    equal(phase, phaser.bulkRegister(10));
    equal(phase, phaser.register());
    try {
        equal(phase, phaser.awaitAdvanceInterruptibly(0));
        equal(phase, phaser.awaitAdvanceInterruptibly(0, 10, SECONDS));
    } catch (Exception ie) {
        unexpected(ie);
    }
    equal(phaser.getUnarrivedParties(), unarriverParties);
    equal(phaser.getRegisteredParties(), registeredParties);
}
 
Example 6
Source File: Basic.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static void checkTerminated(final Phaser phaser) {
    check(phaser.isTerminated());
    int unarriverParties = phaser.getUnarrivedParties();
    int registeredParties = phaser.getRegisteredParties();
    int phase = phaser.getPhase();
    check(phase < 0);
    equal(phase, phaser.arrive());
    equal(phase, phaser.arriveAndDeregister());
    equal(phase, phaser.arriveAndAwaitAdvance());
    equal(phase, phaser.bulkRegister(10));
    equal(phase, phaser.register());
    try {
        equal(phase, phaser.awaitAdvanceInterruptibly(0));
        equal(phase, phaser.awaitAdvanceInterruptibly(0, 10, SECONDS));
    } catch (Exception ie) {
        unexpected(ie);
    }
    equal(phaser.getUnarrivedParties(), unarriverParties);
    equal(phaser.getRegisteredParties(), registeredParties);
}
 
Example 7
Source File: Basic.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static void checkTerminated(final Phaser phaser) {
    check(phaser.isTerminated());
    int unarriverParties = phaser.getUnarrivedParties();
    int registeredParties = phaser.getRegisteredParties();
    int phase = phaser.getPhase();
    check(phase < 0);
    equal(phase, phaser.arrive());
    equal(phase, phaser.arriveAndDeregister());
    equal(phase, phaser.arriveAndAwaitAdvance());
    equal(phase, phaser.bulkRegister(10));
    equal(phase, phaser.register());
    try {
        equal(phase, phaser.awaitAdvanceInterruptibly(0));
        equal(phase, phaser.awaitAdvanceInterruptibly(0, 10, SECONDS));
    } catch (Exception ie) {
        unexpected(ie);
    }
    equal(phaser.getUnarrivedParties(), unarriverParties);
    equal(phaser.getRegisteredParties(), registeredParties);
}
 
Example 8
Source File: SynchronizationStatistics.java    From native-obfuscator with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Tests that waiting multiple times on the same monitor subsequently
 * increases the waited count by the number of subsequent calls and the
 * waited time by a positive number.
 */
private static void testMultiWaitingOnSimpleMonitor() throws Exception {
    final Object lock1 = new Object();

    final Phaser p = new Phaser(2);
    LockerThread lt = newLockerThread(new Runnable() {
        @Override
        public void run() {
            p.arriveAndAwaitAdvance(); // phase[1]
            synchronized(lock1) {
                for (int i = 0; i < 3; i++) {
                    try {
                        lock1.wait(300);
                    } catch (InterruptedException ex) {
                        // ignore
                    }
                    p.arriveAndAwaitAdvance(); // phase[2-4]
                }
            }
            p.arriveAndAwaitAdvance(); // phase[5]
        }
    });

    lt.start();
    ThreadInfo ti1 = mbean.getThreadInfo(lt.getId());
    synchronized(lock1) {
        p.arriveAndAwaitAdvance(); //phase[1]
        waitForThreadState(lt, Thread.State.BLOCKED);
    }
    int phase = p.getPhase();
    while ((p.arriveAndAwaitAdvance() - phase) < 3); // phase[2-4]

    testWaited(ti1, () -> mbean.getThreadInfo(lt.getId()), 3);
    p.arriveAndDeregister(); // phase[5]

    lt.join();

    printok();
}
 
Example 9
Source File: TieredArriveLoops.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
Runnable runner(final Phaser p) {
    return new CheckedRunnable() { public void realRun() {
        int prevPhase = p.register();
        while (!p.isTerminated()) {
            int phase = p.awaitAdvance(p.arrive());
            if (phase < 0)
                return;
            equal(phase, (prevPhase + 1) & Integer.MAX_VALUE);
            int ph = p.getPhase();
            check(ph < 0 || ph == phase);
            prevPhase = phase;
        }
    }};
}
 
Example 10
Source File: ThreadStateController.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private String phaserToString(Phaser p) {
    return "[phase = " + p.getPhase() +
           " parties = " + p.getRegisteredParties() +
           " arrived = " + p.getArrivedParties() + "]";
}
 
Example 11
Source File: SynchronizationStatistics.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tests that waiting multiple times on the same monitor subsequently
 * increases the waited count by the number of subsequent calls and the
 * waited time by a positive number.
 */
private static void testMultiWaitingOnSimpleMonitor() throws Exception {
    System.out.println("testWaitingOnMultipleMonitors");
    final Object lock1 = new Object();

    final Phaser p = new Phaser(2);
    LockerThread lt = newLockerThread(new Runnable() {
        @Override
        public void run() {
            p.arriveAndAwaitAdvance(); // phase[1]
            synchronized(lock1) {
                System.out.println("[LockerThread obtained Lock1]");
                for (int i = 0; i < 3; i++) {
                    try {
                        lock1.wait(300);
                    } catch (InterruptedException ex) {
                        // ignore
                    }
                    p.arriveAndAwaitAdvance(); // phase[2-4]
                }
            }
            p.arriveAndAwaitAdvance(); // phase[5]
        }
    });

    lt.start();
    ThreadInfo ti1 = mbean.getThreadInfo(lt.getId());
    synchronized(lock1) {
        p.arriveAndAwaitAdvance(); //phase[1]
        waitForThreadState(lt, Thread.State.BLOCKED);
    }
    int phase = p.getPhase();
    while ((p.arriveAndAwaitAdvance() - phase) < 3); // phase[2-4]

    testWaited(ti1, () -> mbean.getThreadInfo(lt.getId()), 3);
    p.arriveAndDeregister(); // phase[5]

    lt.join();

    printok();
}
 
Example 12
Source File: ThreadStateController.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private String phaserToString(Phaser p) {
    return "[phase = " + p.getPhase() +
           " parties = " + p.getRegisteredParties() +
           " arrived = " + p.getArrivedParties() + "]";
}
 
Example 13
Source File: SynchronizationStatistics.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tests that waiting multiple times on the same monitor subsequently
 * increases the waited count by the number of subsequent calls and the
 * waited time by a positive number.
 */
private static void testMultiWaitingOnSimpleMonitor() throws Exception {
    System.out.println("testWaitingOnMultipleMonitors");
    final Object lock1 = new Object();

    final Phaser p = new Phaser(2);
    LockerThread lt = newLockerThread(new Runnable() {
        @Override
        public void run() {
            p.arriveAndAwaitAdvance(); // phase[1]
            synchronized(lock1) {
                System.out.println("[LockerThread obtained Lock1]");
                for (int i = 0; i < 3; i++) {
                    try {
                        lock1.wait(300);
                    } catch (InterruptedException ex) {
                        // ignore
                    }
                    p.arriveAndAwaitAdvance(); // phase[2-4]
                }
            }
            p.arriveAndAwaitAdvance(); // phase[5]
        }
    });

    lt.start();
    ThreadInfo ti1 = mbean.getThreadInfo(lt.getId());
    synchronized(lock1) {
        p.arriveAndAwaitAdvance(); //phase[1]
        waitForThreadState(lt, Thread.State.BLOCKED);
    }
    int phase = p.getPhase();
    while ((p.arriveAndAwaitAdvance() - phase) < 3); // phase[2-4]

    testWaited(ti1, () -> mbean.getThreadInfo(lt.getId()), 3);
    p.arriveAndDeregister(); // phase[5]

    lt.join();

    printok();
}
 
Example 14
Source File: ThreadStateController.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private String phaserToString(Phaser p) {
    return "[phase = " + p.getPhase() +
           " parties = " + p.getRegisteredParties() +
           " arrived = " + p.getArrivedParties() + "]";
}
 
Example 15
Source File: SynchronizationStatistics.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tests that waiting multiple times on the same monitor subsequently
 * increases the waited count by the number of subsequent calls and the
 * waited time by a positive number.
 */
private static void testMultiWaitingOnSimpleMonitor() throws Exception {
    System.out.println("testWaitingOnMultipleMonitors");
    final Object lock1 = new Object();

    final Phaser p = new Phaser(2);
    LockerThread lt = newLockerThread(new Runnable() {
        @Override
        public void run() {
            p.arriveAndAwaitAdvance(); // phase[1]
            synchronized(lock1) {
                System.out.println("[LockerThread obtained Lock1]");
                for (int i = 0; i < 3; i++) {
                    try {
                        lock1.wait(300);
                    } catch (InterruptedException ex) {
                        // ignore
                    }
                    p.arriveAndAwaitAdvance(); // phase[2-4]
                }
            }
            p.arriveAndAwaitAdvance(); // phase[5]
        }
    });

    lt.start();
    ThreadInfo ti1 = mbean.getThreadInfo(lt.getId());
    synchronized(lock1) {
        p.arriveAndAwaitAdvance(); //phase[1]
        waitForThreadState(lt, Thread.State.BLOCKED);
    }
    int phase = p.getPhase();
    while ((p.arriveAndAwaitAdvance() - phase) < 3); // phase[2-4]

    testWaited(ti1, () -> mbean.getThreadInfo(lt.getId()), 3);
    p.arriveAndDeregister(); // phase[5]

    lt.join();

    printok();
}
 
Example 16
Source File: SynchronizationStatistics.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tests that waiting multiple times on the same monitor subsequently
 * increases the waited count by the number of subsequent calls and the
 * waited time by a positive number.
 */
private static void testMultiWaitingOnSimpleMonitor() throws Exception {
    System.out.println("testWaitingOnMultipleMonitors");
    final Object lock1 = new Object();

    final Phaser p = new Phaser(2);
    LockerThread lt = newLockerThread(new Runnable() {
        @Override
        public void run() {
            p.arriveAndAwaitAdvance(); // phase[1]
            synchronized(lock1) {
                System.out.println("[LockerThread obtained Lock1]");
                for (int i = 0; i < 3; i++) {
                    try {
                        lock1.wait(300);
                    } catch (InterruptedException ex) {
                        // ignore
                    }
                    p.arriveAndAwaitAdvance(); // phase[2-4]
                }
            }
            p.arriveAndAwaitAdvance(); // phase[5]
        }
    });

    lt.start();
    ThreadInfo ti1 = mbean.getThreadInfo(lt.getId());
    synchronized(lock1) {
        p.arriveAndAwaitAdvance(); //phase[1]
        waitForThreadState(lt, Thread.State.BLOCKED);
    }
    int phase = p.getPhase();
    while ((p.arriveAndAwaitAdvance() - phase) < 3); // phase[2-4]

    testWaited(ti1, () -> mbean.getThreadInfo(lt.getId()), 3);
    p.arriveAndDeregister(); // phase[5]

    lt.join();

    printok();
}
 
Example 17
Source File: ThreadStateController.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private String phaserToString(Phaser p) {
    return "[phase = " + p.getPhase() +
           " parties = " + p.getRegisteredParties() +
           " arrived = " + p.getArrivedParties() + "]";
}
 
Example 18
Source File: ThreadStateController.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private String phaserToString(Phaser p) {
    return "[phase = " + p.getPhase() +
           " parties = " + p.getRegisteredParties() +
           " arrived = " + p.getArrivedParties() + "]";
}
 
Example 19
Source File: SynchronizationStatistics.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tests that waiting multiple times on the same monitor subsequently
 * increases the waited count by the number of subsequent calls and the
 * waited time by a positive number.
 */
private static void testMultiWaitingOnSimpleMonitor() throws Exception {
    System.out.println("testWaitingOnMultipleMonitors");
    final Object lock1 = new Object();

    final Phaser p = new Phaser(2);
    LockerThread lt = newLockerThread(new Runnable() {
        @Override
        public void run() {
            p.arriveAndAwaitAdvance(); // phase[1]
            synchronized(lock1) {
                System.out.println("[LockerThread obtained Lock1]");
                for (int i = 0; i < 3; i++) {
                    try {
                        lock1.wait(300);
                    } catch (InterruptedException ex) {
                        // ignore
                    }
                    p.arriveAndAwaitAdvance(); // phase[2-4]
                }
            }
            p.arriveAndAwaitAdvance(); // phase[5]
        }
    });

    lt.start();
    ThreadInfo ti1 = mbean.getThreadInfo(lt.getId());
    synchronized(lock1) {
        p.arriveAndAwaitAdvance(); //phase[1]
        waitForThreadState(lt, Thread.State.BLOCKED);
    }
    int phase = p.getPhase();
    while ((p.arriveAndAwaitAdvance() - phase) < 3); // phase[2-4]

    testWaited(ti1, () -> mbean.getThreadInfo(lt.getId()), 3);
    p.arriveAndDeregister(); // phase[5]

    lt.join();

    printok();
}
 
Example 20
Source File: ThreadStateController.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private String phaserToString(Phaser p) {
    return "[phase = " + p.getPhase() +
           " parties = " + p.getRegisteredParties() +
           " arrived = " + p.getArrivedParties() + "]";
}