Multithreading Interview Questions
start(): In simple words, the start() method is used to start or begin the execution of
a newly created thread. When the start() method is called, a new thread is created
and this newly created thread executes the task that is kept in the run() method. One
can call the start() method only once.
run(): In simple words, the run() method is used to start or begin the execution of the
same thread. When the run() method is called, no new thread is created as in the case
of the start() method. This method is executed by the current thread. One can call the
run() method multiple times.
13. Explain thread pool?
A Thread pool is simply a collection of pre-initialized or worker threads at the start-up
that can be used to execute tasks and put back in the pool when completed. It is
referred to as pool threads in which a group of fixed-size threads is created. By
reducing the number of application threads and managing their lifecycle, one can
mitigate the issue of performance using a thread pool. Using threads, performance
can be enhanced and better system stability can occur. To create the thread pools,
java.util.concurrent.Executors class usually provides factory methods.
Dostları ilə paylaş: