JavaGian java tutorial and java interview question and answer

JavaGian , Free Online Tutorials, JavaGian provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, ajax, core java, sql, python, php, c language etc. for beginners and professionals.

Showing posts with label Daemon-thread. Show all posts
Showing posts with label Daemon-thread. Show all posts

Daemon thread in java with example

7:47 AM
Daemon threads are low priority background threads which provide services to user threads. It’s life depends on user threads. If no user thread is running then JVM can exit even if daemon threads are running. JVM do not wait for daemon threads to finish. Daemon threads perform background tasks such as garbage collection, finalizer  etc. The only purpose of daemon thread is to serve user thread so if there are no user threads, there is no point of JVM to run these threads, that’s why JVM exits once there are no user threads. Two method related to daemon thread Public void setDaemon(boolean status) : This method can be used to mark thread as user  or daemon thread. If you put setDaemon(true), it makes thread as daemon.   Public boolean isDaemon()  This method can be used to check if thread is daemon or not. Daemon Thread example: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 2...

.