Reputation: 477
If I create a Daemon thread from my program (a non-daemon process), are the heap and perm gen memory spaces shared with the new thread or is it allocated anew?
If the daemon thread gets its own spaces, are the JVM memory tuning args like max heap size, etc respected in the creation of the new thread?
Upvotes: 1
Views: 1829
Reputation: 116918
are the heap and perm gen memory spaces shared with the new thread or is it allocated anew?
All threads (daemon status does not matter) share heap and perm memory spaces. Each thread has it's own stack space which it uses to store method fields and the call stack. You can tune the size of the allocated per-thread stack space by changing JVM arguments. But even these stack areas are part of the general JVM heap space.
Threads also have a memory cache when it is running in a separate CPU. The per-CPU memory cache is used for performance reasons so updates can be made to local CPU memory for speed reasons without having to synchronize the information to central storage on every access. But these caches still read from and write to the general JVM memory space.
For more information about what daemon-thread really means, see @Peter's answer.
Upvotes: 8
Reputation: 533790
The ONLY significant difference between a daemon thread and a normal thread is whether it will prevent the process from being stopped. A normal thread keeps the JVM running, a daemon does not.
Daemon threads have
BTW: Other differences to be pedantic,
true
Upvotes: 3