← Back to libraryQuestion 32 of 273
JavaIntermediate

Daemon Threads

📖 Detailed Explanation:

Daemon threads are low-priority background threads that provide services to user threads (like Garbage Collection). The JVM does NOT wait for daemon threads to finish before shutting down; if only daemon threads remain, the JVM exits immediately. Daemon threads are useful for cleanup or background monitoring tasks.

🌍 Real-World Example:

The janitorial staff in an office building. When all employees (user threads) go home, the janitors (daemon threads) stop working too, even if they aren't finished cleaning.

🎯 Scenario-Based Interview Question:

Can you convert a running thread to a daemon thread after it has started?