Semaphore

Semaphore is another way of synchronizing threads for solving the producer-consumer problem or guarding a critical section. Ignite's distributed semaphore data structure is IgniteSemaphore.

We can define a semaphore using the following syntax:

IgniteSemaphore semaphore = ignite.semaphore( "mySemaphore", // semaphore name. 20, // permits. true, // Release acquired permits if node, that owned them, left topology. true // Create if it doesn't exist.);

IgniteSemaphore has two important methods:

  • acquire() and other variants, such as acquire(int permits), tryAcquire(int permits), and acquireUninterruptibly(). Acquires a permit, or a given number of permits for acquire(int permits) and tryAcquire(int permits), from this semaphore,

Get Apache Ignite Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.