Repository: ignite Updated Branches: refs/heads/master 60c056098 -> f4e4f77d1
ignite-6009 Review. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f4e4f77d Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f4e4f77d Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f4e4f77d Branch: refs/heads/master Commit: f4e4f77d17002bd8c7eb3ab89587f5b0bd838d92 Parents: dadc42f Author: Andrey Gura <[email protected]> Authored: Mon Aug 21 16:06:30 2017 +0300 Committer: Andrey Gura <[email protected]> Committed: Mon Aug 21 16:14:06 2017 +0300 ---------------------------------------------------------------------- .../datastructures/IgniteSemaphoreExample.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/f4e4f77d/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSemaphoreExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSemaphoreExample.java b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSemaphoreExample.java index 1280464..99403dc 100644 --- a/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSemaphoreExample.java +++ b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSemaphoreExample.java @@ -47,11 +47,12 @@ public class IgniteSemaphoreExample { */ public static void main(String[] args) { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { - // Number of producers; should be equal to number of consumers. - // This value should not exceed overall number of compute threads in a cluster, - // otherwise blocking consumer jobs can occupy all the threads leading to deadlock. - int producerConsumerCount = - ignite.configuration().getPublicThreadPoolSize() * ignite.cluster().forServers().nodes().size() / 2; + int nodeCount = ignite.cluster().forServers().nodes().size(); + + // Number of producers should be equal to number of consumers. + // This value should not exceed overall number of public thread pools in a cluster, + // otherwise blocking consumer jobs can occupy all the threads leading to starvation. + int jobCount = ignite.configuration().getPublicThreadPoolSize() * nodeCount / 2; System.out.println(); System.out.println(">>> Cache atomic semaphore example started."); @@ -66,17 +67,17 @@ public class IgniteSemaphoreExample { IgniteSemaphore semaphore = ignite.semaphore(semaphoreName, 0, false, true); // Start consumers on all cluster nodes. - for (int i = 0; i < producerConsumerCount; i++) + for (int i = 0; i < jobCount; i++) ignite.compute().runAsync(new Consumer(semaphoreName)); // Start producers on all cluster nodes. - for (int i = 0; i < producerConsumerCount; i++) + for (int i = 0; i < jobCount; i++) ignite.compute().runAsync(new Producer(semaphoreName)); System.out.println("Master node is waiting for all other nodes to finish..."); // Wait for everyone to finish. - syncSemaphore.acquire(2 * producerConsumerCount); + syncSemaphore.acquire(2 * jobCount); } System.out.flush();
