Java Timer vs ExecutorService?

前端 未结 6 1457
孤独总比滥情好
孤独总比滥情好 2020-11-21 23:51

I have code where I schedule a task using java.util.Timer. I was looking around and saw ExecutorService can do the same. So this question here, hav

6条回答
  •  感动是毒
    2020-11-22 00:43

    ExecutorService is newer and more general. A timer is just a thread that periodically runs stuff you have scheduled for it.

    An ExecutorService may be a thread pool, or even spread out across other systems in a cluster and do things like one-off batch execution, etc...

    Just look at what each offers to decide.

提交回复
热议问题