Synchronous executor interface

Robert Engels rengels at ix.netcom.com
Sun Aug 6 22:05:37 UTC 2023


That is nonsensical.  It would mean you would have to pass the supplier to multi threads of execution or you would only have a single execution possible. 

So the interface does nothing in the case. Use a semaphore if you need to limit concurrency - call the supplier directly if you don’t. 

You added a layer that doesn’t do anything but is obscure the code/intent. 

> On Aug 6, 2023, at 4:33 PM, Attila Kelemen <attila.kelemen85 at gmail.com> wrote:
> 
> 
> Robert Engels <rengels at ix.netcom.com> ezt írta (időpont: 2023. aug. 6., V, 23:27):
>> But tbh - I don’t really know what you are asking for because you talk about limiting the number of requests but making it called on the same thread. I don’t even think that is possible. 
>> 
> 
> A possible implementation of such an interface could limit concurrency with a semaphore like this:
> 
> ```
> class LimitedSynchronousExecutor implements SynchronousExecutor {
>   private final Semaphore semaphore;
>   
>   public LimitedSynchronousExecutor(int maxConcurrency) {
>     semaphore = new Semaphore(maxConcurrency);
>   }
>   
>   @Override
>   public <T> T execute(Supplier<? extends T> action) {
>     semaphore.acquireUninterruptibly();
>     try {
>       return action.get();
>     } finally {
>       semaphore.release();
>     }
>   }
> }
> ``` 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20230806/43d19479/attachment.htm>


More information about the loom-dev mailing list