<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>