Search code examples
javascalabilityconceptual

Best way to check status of test every x minutes?


I'm currently using an API in which an email test is sent out, and about 25 minutes later it is finished. This time can vary depending on server load (The API calls are outsourced to a different company).

With the feature we're developing, we may be creating about 1,000 test a day, and I was wondering whats an effective way to check on the status of each of those tests with Java? If I were to schedule a task, I assume that would leave a thread waiting for x amount of minutes, which doesn't seem very scalable.


Solution

  • You probably want to use the ScheduledThreadPoolExecutor class.

    A ThreadPoolExecutor that can additionally schedule commands to run after a given delay, or to execute periodically.

    Flexible features:

    • Schedule multiple jobs using different delays.
    • You can use a convenient TimeUnit when scheduling.
    • Ability to decide how many jobs can be executed simultaneously.
    • You only need to implement the Runnable interface (which defines a run method).
    • Threads are reused, and created using a ThreadFactory (optional).

    More details and examples can be found here.