<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div dir="ltr"></div><div dir="ltr">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. </div><div dir="ltr"><br></div><div dir="ltr">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. </div><div dir="ltr"><br></div><div dir="ltr">You added a layer that doesn’t do anything but is obscure the code/intent. </div><div dir="ltr"><br><blockquote type="cite">On Aug 6, 2023, at 4:33 PM, Attila Kelemen <attila.kelemen85@gmail.com> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><div dir="ltr"><div dir="ltr">Robert Engels <<a href="mailto:rengels@ix.netcom.com">rengels@ix.netcom.com</a>> ezt írta (időpont: 2023. aug. 6., V, 23:27):<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div dir="ltr"></div><div dir="ltr">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. </div><div dir="ltr"><br></div></div></blockquote><div><br></div><div>A possible implementation of such an interface could limit concurrency with a semaphore like this:</div><div><br></div><div>```</div>class LimitedSynchronousExecutor implements SynchronousExecutor {<br> private final Semaphore semaphore;<br> <br> public LimitedSynchronousExecutor(int maxConcurrency) {<br> semaphore = new Semaphore(maxConcurrency);<br> }<br> <br> @Override<br> public <T> T execute(Supplier<? extends T> action) {<br> semaphore.acquireUninterruptibly();<br> try {<br> return action.get();<br> } finally {<br> semaphore.release();<br> }<br> }<br><div>}</div><div>``` </div></div></div>
</div></blockquote></body></html>