I know that Thread and Task are in different abstraction-level.But anyway,I’m still confused that what’s the relationship of them.And,by the way,I think that the Task tells how to do a job and the Thread actually excute the job according to a Task instance.Is my understanding correct?thank u^
I know that Thread and Task are in different abstraction-level.But anyway,I’m still confused that
Share
I assume by Task you mean
RunnableandCallable. The relationship is simple:might – because you don’t need a separate thread to execute tasks (well, technically, everything runs inside a thread – you don’t need a separate one)
multiple – thread can be reused; it can run multiple tasks from a collection like queue
Typically one thread executes one
Runnablepassed toThreadconstructor or multipleCallables passed toExecutorService(wrapping thread pool in most cases).