hazelcast / hazelcast/hz-docs

Docs: Feedback for ISemaphore

Open
#808 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
11
Forks
112
Avg merge
20h 29m
Merged PRs (30d)
19

Description

Hi, I have some feedback about [this page](https://github.com/hazelcast/hz-docs/edit/main/docs/modules/data-structures/pages/isemaphore.adoc)

The _Example Semaphore Code_ section is trying to explain the usage of semaphores in controlling the total thread count. However I don't see any thread in the code except the main thread. It seems that something like a ExecutotService is missing in the code:
`

HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();

ISemaphore semaphore = hazelcastInstance.getCPSubsystem().getSemaphore( "semaphore" );
IAtomicLong resource = hazelcastInstance.getCPSubsystem().getAtomicLong( "resource" );
semaphore.init(4);
ExecutorService executorService = ...;
for ( int k = 0 ; k < 1000 ; k++ ) {
System.out.println( "At iteration: " + k + ", Active Threads: " + resource.get() );
semaphore.acquire();
executorService.submit(()->{
try {
resource.incrementAndGet();
Thread.sleep( 1000 );
resource.decrementAndGet();
} finally {
semaphore.release();
}
});
}
System.out.println("Finished");`

thanks

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.