Reputation: 1231
Java has daemon thread to monitor memory usage and do the gc task. From jstack I see
"main" #1 prio=5 os_prio=0 tid=0x00007f34b000e000 nid=0x808 waiting on condition [0x00007f34b6f02000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
....
"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00007f34b0023000 nid=0x809 runnable
"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00007f34b0024800 nid=0x80a runnable
"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x00007f34b0026800 nid=0x80b runnable
But speaking of python, I wrote a
#!/usr/bin/env python
import gc
import time
gc.enable()
while True:
print "This prints once a minute."
time.sleep(60)
I saw the the python process has only one thread,
$ cat /proc/1627/status
Name: python
...
Threads: 1
The question is, why python doesn't have gc thread like Java? Then which thread does the gc task?
Upvotes: 2
Views: 714
Reputation: 8399
If you start java with -XX:+UseSerialGC
options you will not see any GC thread.
For single threaded GC algorithm application thread can be used to do GC activities.
Dedicated threads required for
Upvotes: 2