Objective: Monitor 5 json URLs every 5 seconds with 5 threads running parallel.
I want to run Multiple parallel threads to monitor JSON URLs at an interval of n-seconds each. I am using ScheduledExecutorService
for this.
ScheduledExecutorService executor = Executors.newScheduledThreadPool(5);
for(NetworkBwXmlObject x : xmlDsList) {
executor.scheduleAtFixedRate(new processJsonUrl(x.getJsonUrl(),x.getId(), ctx), 0, 5, TimeUnit.SECONDS);
}
class processJsonUrl implements Runnable {
}
Is this the right way to create 5 threads to monitor 5 URLS. I don't want to use a thread pool here. All 5 threads have to be active till the lifecycle of the application.
Can ScheduledExecutorService
help in my scenario or there is an alternate way to achieve this?
Thanks
ScheduledExecutorService is a thread pool and it will do what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With