MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / startGCThread

Method startGCThread

vm/JavaAPI/src/java/lang/System.java:69–103  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

67 private static boolean gcShouldLoop = true;
68 // invoked from native code
69 private static void startGCThread() {
70 if(!startedGc) {
71 startedGc = true;
72 // not ideal but does the job for now, since gc is pretty efficient the cost is very low
73 gcThreadInstance = new Thread("GC Thread") {
74 public void run() {
75 synchronized(LOCK) {
76 // wait two seconds initially so startup won't be hindered by slow waits
77 try {
78 LOCK.wait(2000);
79 } catch (InterruptedException ex) {
80 }
81 }
82 gcShouldLoop = true;
83 while(gcShouldLoop) {
84 try {
85 System.gcMarkSweep();
86 synchronized(LOCK) {
87 if(forceGc || isHighFrequencyGC()) {
88 forceGc = false;
89 LOCK.wait(200);
90 } else {
91 LOCK.wait(30000);
92 }
93 }
94 } catch (InterruptedException ex) {
95 }
96 }
97 startedGc = false;
98 gcThreadInstance = null;
99 }
100 };
101 gcThreadInstance.start();
102 }
103 }
104
105 /**
106 * Invoked from native code

Callers 1

gcMethod · 0.95

Calls 1

startMethod · 0.65

Tested by

no test coverage detected