multithreading - Concurrent execution of scheduled tasks in Java -
i have timertask designed gather metrics @ specific interval. possible period of task execution less time of task execution (occasionally if times out , gets delayed).
is there way execute multiple timertasks or runnables, threads, etc. concurrently without waiting previous task complete?
i know timer uses single thread, , scheduledthreadpoolexecutor delay execution regardless of rate.
thanks.
i recommend using executors.newcachedthreadpool()
or newcachedthreadpool(threadfactory threadfactory)
own thread factory, in conjuction timer. code should this
executor executor = executors.newcachedthreadpool(); timer time = new timer(); timer.scheduleatfixedrate(new timertask() { public void run() { executor.execute(new runnable() { public void run() { //your business logic } }); } }, delay, period);
this way schedule tasks period , run concurrently.
Comments
Post a Comment