Link to home
Create AccountLog in
Avatar of Jay Roy
Jay RoyFlag for United States of America

asked on

ExecutorService v/s ScheduledExService

hi
i was reading through ExecutorService v/s ScheduledExecutorService
In what scenario do i use ExecutorService  and in what scenarios do i use
ScheduledExecutorService ?
Can anyone give a simple example?
Can i create a pool of threads and use it with scheduledExecutorService?

thanks
Avatar of cmalakar
cmalakar
Flag of India image

>>In what scenario do i use ExecutorService  and in what scenarios do i use
ScheduledExecutorService ?

When you want to schedule the task after certain delay or some period, you should use ScheduledExecutorService.

And if you want to run them immediately, then use Executor Service.
And ExecutorService, will run them immediately only if there are threads available in its pool.

Else, it will wait for the threads to become free.
>>Can i create a pool of threads and use it with scheduledExecutorService?

Only if you want have tasks to run with some delay. Otherwise I dont see a need.
Avatar of Jay Roy

ASKER

ok, let me give specific example, if i have 80 update queries to execute is it a good practice to use
ExecutorService (feeding task to a pool of threads) or do i use ScheduledExecutorService and run the tasks every microsecond ?
 Which one will be more faster and better design?

thanks
As I said, unless there is a specific reason I will not go for ScheduledExecutorService.

Executor Service should suffice your requirement.

As I said in your last question, make each task, to use its own hibernate session.
Avatar of Jay Roy

ASKER

>>>When you want to schedule the task after certain delay or some period, you should use ScheduledExecutorService.

can you provide an example(real world)?

thanks.
ASKER CERTIFIED SOLUTION
Avatar of cmalakar
cmalakar
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Jay Roy

ASKER

ok makes sense, thanks