Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

9
  • You want the execution to overlap, right? So ScheduledThreadPoolExecutor won't work for you. If that is the case... why? Surely you can make the request asynchronously fast enough so that overlapping is not a problem. Then even Timer would work. Commented Nov 21, 2019 at 12:06
  • You only need threading in handling the responses, if at all. Making the requests can be centralised. Commented Nov 21, 2019 at 13:10
  • @Theraot : Some threads in my app will call 3-rd party API through a singleton REST client. I want that no matter which thread calls this client, an overlap of 100ms between calls. I do not think that timer will do the Job or I misunderstood something. Commented Nov 21, 2019 at 13:31
  • @Caleth : multiple threads call call the REST client. Commented Nov 21, 2019 at 13:31
  • @Rouliboy overlap means that it will awake a thread to make a request even if there are other threads that haven't ended. That is, if you have an interval of 100ms without overlap, they will queue up when it takes too long to make the request. On the other hand, an interval of 100ms with overlap can have multiple threads requesting at the same time when they take longer than 100ms to make the request. If you do not want overlap (i.e. you want them to queue up), then Timer will work. Now, are requests slow enough that overlap matters? Using Timer, there would be no queue, if requests are fast. Commented Nov 21, 2019 at 13:46