Is garbage collector a daemon thread?
Is garbage collector a daemon (background) thread?开发者_运维技巧
Thanks.
I will assume yes, Garbage collector thread is a daemon thread. Daemon thread is a low priority thread which runs intermittently in the back ground doing the garbage collection operation or other requests for the java runtime system.
It's not a thread from a java.lang.Thread
perspective at least.
Yes: http://www.javaperspective.com/daemon-threads.html : (Daemon threads are considered as threads that run in the background and they are generally used as service providers for user threads. For example, the Java garbage collector is a daemon thread)
on jdk 1.8 following threads are listed with
ThreadMXBean mxbean = ManagementFactory.getThreadMXBean();
for(long id:mxbean.getAllThreadIds())
System.out.println(mxbean.getThreadInfo(id));
Output -
- "Attach Listener" Id=5 RUNNABLE
- "Signal Dispatcher" Id=4 RUNNABLE
- "Finalizer" Id=3 WAITING on java.lang.ref.ReferenceQueue$Lock@63947c6b
- "Reference Handler" Id=2 WAITING on java.lang.ref.Reference$Lock@2b193f2d
- "main" Id=1 RUNNABLE
There is no GC thread. It can safely be said garbage collection process is native.
A daemon thread is also a thread that continues to run even after the JVM exits. From Oracle documentation When a Java Virtual Machine starts up, there is usually a single non-daemon thread (which typically calls the method named main of some designated class). The Java Virtual Machine continues to execute threads until either of the following occurs: •The exit method of class Runtime has been called and the security manager has permitted the exit operation to take place. •All threads that are not daemon threads have died, either by returning from the call to the run method or by throwing an exception that propagates beyond the run method.
So if GC is a daemon thread, it should be a native thread spawned by the java run time, but can continue to run after he JVM exits
精彩评论