There are two types of threads in java. One is User
Thread and another one is Daemon Thread. User threads are
high priority threads which always run in foreground. Whereas Daemon threads are low priority threads
which always run in background. User threads are designed to do some specific
task whereas daemon threads are used to perform some supporting tasks.
Difference Between User Threads Vs Daemon Threads in
Java
1) User threads are created by the application (user)
to perform some specific task. Whereas daemon threads are mostly created by the JVM to
perform some background tasks like garbage collection.
2) JVM will wait for user threads to finish their
tasks. JVM will not exit until all user threads finish their tasks. On the
other side, JVM will not wait for daemon threads to finish their tasks. It will
exit as soon as all user threads finish their tasks.
3) User threads are high priority threads,
they are designed mainly to execute some important task in an application.
Whereas daemon threads are less priority threads. They are
designed to serve the user threads.
4) User threads are foreground threads.
They always run in foreground and perform some specific task assigned to them. Whereas
daemon threads are background threads. They always run in
background and act in a supporting role to user threads.
No comments:
Post a Comment