Emanuel Kadziela wrote:A Semaphore sounds like what you could use. It is a way to restrict the number of threads which will be allowed to concurrently run.
tuntun tuntuns wrote:
Emanuel Kadziela wrote:A Semaphore sounds like what you could use. It is a way to restrict the number of threads which will be allowed to concurrently run.
Hi Emanuel,
Could you Please post the code as I have done , That will be really helpful to understand.
sunder Nagar wrote:
Now Please advise is there any other way also by which we can achieve the same thing like through executors, semaphores, Locks..!! Please advise
sunder Nagar wrote:
tuntun tuntuns wrote:
Emanuel Kadziela wrote:A Semaphore sounds like what you could use. It is a way to restrict the number of threads which will be allowed to concurrently run.
Hi Emanuel,
Could you Please post the code as I have done , That will be really helpful to understand.
Hi Folks,
Please advise that either by semaphore how we can build the same approach or any other means of executor or latcher ,Please advise
As others has mentioned, the Semaphore class can also be used in a similar fashion -- just use the acquire() and release() methods in place of your claim and release methods. You will also have to set the permits to only one -- to prevent parallel execution. And set the fairness flag on, in order to have it queued up.
Personally, I think using the Semaphore class is an overkill versus the ReentrantLock class. You don't need the capability to handle more than one permit -- and the Semaphore class doesn't nest like the ReentrantLock class can.
Henry
sunder Nagar wrote:
Hi Henry,
Thanks a lot, Please post the code as I have done in term of Reentrant Lock that will be a great help, just convert my piece of code into the Reentrant one that will be a great help to understand.Thanks inadvance.
Henry Wong wrote:
First of all, you haven't shown any code that uses your AccessGate class, hence, nothing to convert from using the AccessGate class to the ReentrantLock class. Second, you wrote your own locking class -- isn't using a lock much easier to do? Do really need an example of using a lock? ... plus there is also an example in the JavaDocs.
Henry
sunder Nagar wrote:
Now please advise that if there is any other way to make access gate in any alternative way that is through re entrant or executor framework ..!!
Really?!? It will likely take five minutes to port this code from using the AccessGate class to using the ReentrantLock class. Ten minutes if you add the time to read the JavaDoc.
Just do it. It really isn't that hard.
Henry