| 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 |