163.
164.
165.
Explain the different types of Threads in Java.
Answer:
There are 2 types of threads–User defined Threads and Daemon
threads
User defined threads are those that
are created programmatically
by a user. These are high priority threads. The JVM waits for
these threads to finish.
Daemon threads
are mostly created by the JVM, although a
user–defined thread can be explicitly
set to be a daemon thread
as well. Daemon threads are usually used for background
processes such as Garbage Collection. As soon as all Non–
Daemon
threads stop running, the JVM stops running and does
not wait for the Daemon threads to stop.
Can the run method be invoked directly without invoking
the start method?
Answer:
The run() method can directly be invoked instead of invoking
the start() method. However, this
will not spawn a new thread,
the code within the run() method will be executed in the same
thread that invokes it. The start() method
is responsible for
spawning a new thread and needs to be invoked.
Do'stlaringiz bilan baham: