List of usage examples for java.lang Runtime gc
public native void gc();
From source file:com.talis.entity.TestUtils.java
public static void tryForceGC() { Runtime r = Runtime.getRuntime(); for (int i = 0; i < 10; i++) { r.gc(); }// www . j a v a 2 s.c om }
From source file:com.fizzed.rocker.ConstantPoolMain.java
static public void garbageCollectAndPrintMemory() { //Getting the runtime reference from system Runtime runtime = Runtime.getRuntime(); runtime.gc(); //System.out.println("##### Heap utilization statistics [MB] #####"); //Print used memory System.out.println("Used Memory: " + (runtime.totalMemory() - runtime.freeMemory())); //Print free memory /**/*from www . j a va2s . c o m*/ System.out.println("Free Memory:" + runtime.freeMemory()); //Print total available memory System.out.println("Total Memory:" + runtime.totalMemory()); //Print Maximum available memory System.out.println("Max Memory:" + runtime.maxMemory()); */ }
From source file:com.fizzed.rocker.bin.ConstantPoolMain.java
static public void garbageCollectAndPrintMemory() { //Getting the runtime reference from system Runtime runtime = Runtime.getRuntime(); runtime.gc(); //System.out.println("##### Heap utilization statistics [MB] #####"); //Print used memory System.out.println("Used Memory: " + (runtime.totalMemory() - runtime.freeMemory())); //Print free memory /**//w w w. j av a 2s . c o m System.out.println("Free Memory:" + runtime.freeMemory()); //Print total available memory System.out.println("Total Memory:" + runtime.totalMemory()); //Print Maximum available memory System.out.println("Max Memory:" + runtime.maxMemory()); */ }
From source file:net.ymate.platform.commons.util.RuntimeUtils.java
/** * //from www .j av a2 s .c o m * * @return ?? */ public static final long gc() { Runtime rt = Runtime.getRuntime(); long lastUsed = rt.totalMemory() - rt.freeMemory(); rt.gc(); return lastUsed - rt.totalMemory() + rt.freeMemory(); }
From source file:net.ymate.platform.core.util.RuntimeUtils.java
/** * /*from w w w. j av a2 s . c o m*/ * * @return ?? */ public static long gc() { Runtime rt = Runtime.getRuntime(); long lastUsed = rt.totalMemory() - rt.freeMemory(); rt.gc(); return lastUsed - rt.totalMemory() + rt.freeMemory(); }
From source file:com.titilink.camel.rest.util.OtherUtil.java
/** * ?// w w w. j a v a2 s .c om */ public static void jvmGC() { //??? Runtime rt = Runtime.getRuntime(); rt.gc(); }
From source file:jfs.sync.encryption.JFSEncryptedStream.java
public static OutputStream createOutputStream(long compressionLimit, OutputStream baseOutputStream, long length, Cipher cipher) throws IOException { OutputStream result = null;/* w w w . ja v a 2 s. c o m*/ Runtime runtime = Runtime.getRuntime(); long freeMem = runtime.totalMemory() / SPACE_RESERVE; if (length >= freeMem) { if (log.isWarnEnabled()) { log.warn("JFSEncryptedStream.createOutputStream() GC " + freeMem + "/" + runtime.maxMemory()); } // if runtime.gc(); freeMem = runtime.totalMemory() / SPACE_RESERVE; } // if if ((length < compressionLimit) && (length < freeMem)) { result = new JFSEncryptedStream(baseOutputStream, cipher); } else { if (length < freeMem) { if (log.isInfoEnabled()) { log.info("JFSEncryptedStream.createOutputStream() not compressing"); } // if } else { if (log.isWarnEnabled()) { log.warn("JFSEncryptedStream.createOutputStream() due to memory constraints (" + length + "/" + freeMem + ") not compressing"); } // if } // if ObjectOutputStream oos = new ObjectOutputStream(baseOutputStream); oos.writeByte(COMPRESSION_NONE); oos.writeLong(length); oos.flush(); result = baseOutputStream; if (cipher != null) { result = new CipherOutputStream(result, cipher); } // if } // if return result; }
From source file:fr.inria.atlanmod.neoemf.benchmarks.query.Query.java
default V callWithMemoryUsage() throws Exception { V result;//from ww w .j av a2 s .c om Runtime runtime = Runtime.getRuntime(); runtime.gc(); long initialUsedMemory = runtime.totalMemory() - runtime.freeMemory(); log.info("Used memory before call: {}", FileUtils.byteCountToDisplaySize(initialUsedMemory)); result = callWithTime(); runtime.gc(); long finalUsedMemory = runtime.totalMemory() - runtime.freeMemory(); log.info("Used memory after call: {}", FileUtils.byteCountToDisplaySize(finalUsedMemory)); log.info("Memory use increase: {}", FileUtils.byteCountToDisplaySize(finalUsedMemory - initialUsedMemory)); return result; }
From source file:org.sakaiproject.content.impl.serialize.impl.test.ProfileSerializerTest.java
/** * Test method for//from ww w .j a v a 2 s . com * {@link org.sakaiproject.content.impl.serialize.impl.Type1BaseContentCollectionSerializer#parse(org.sakaiproject.entity.api.serialize.SerializableEntity, java.lang.String)}. * * @throws Exception */ @Test public final void testParse() throws Exception { Type1BaseContentCollectionSerializer t1 = new Type1BaseContentCollectionSerializer(); t1.setTimeService(new MockTimeService()); MockSerializableCollectionAcccess sc = new MockSerializableCollectionAcccess(); byte[] serialized = null; Runtime r = Runtime.getRuntime(); r.gc(); Thread.sleep(2000); { long start = System.currentTimeMillis(); long ms = r.freeMemory(); for (int i = 0; i < 16000; i++) { serialized = t1.serialize(sc); } long me = r.freeMemory(); long m = ms - me; long end = System.currentTimeMillis(); long t = (end - start); log.info("Write 16000 Entities took " + t + "ms "); log.info("Write 16000 Entities took " + (t * 1000) / 16000 + " us/entity "); log.info("Write 16000 Entities took " + m + " bytes overhead "); log.info("Write 16000 Entities took " + (m / 16000) + " bytes/entity overhead "); } r.gc(); Thread.sleep(2000); { long start = System.currentTimeMillis(); long ms = r.freeMemory(); for (int i = 0; i < 16000; i++) { t1.parse(sc, serialized); } long me = r.freeMemory(); long m = ms - me; long end = System.currentTimeMillis(); long t = (end - start); log.info("Read 16000 Entities took " + t + "ms "); log.info("Read 16000 Entities took " + (t * 1000) / 16000 + " us/entity "); log.info("Read 16000 Entities took " + m + " bytes overhead "); log.info("Read 16000 Entities took " + (m / 16000) + " bytes/entity overhead "); } sc.check(); }
From source file:MIDletProps.java
/** * Show the value of the properties//w ww .j a va 2 s . c om */ public void startApp() { Runtime runtime = Runtime.getRuntime(); runtime.gc(); long free = runtime.freeMemory(); long total = runtime.totalMemory(); propbuf = new StringBuffer(50); props = new Form("System Properties"); props.append("Free Memory = " + free + "\n"); props.append("Total Memory = " + total + "\n"); props.append(showProp("microedition.configuration")); props.append(showProp("microedition.platform")); props.append(showProp("microedition.locale")); props.append(showProp("microedition.encoding")); props.append(showProp("microedition.encodingClass")); props.append(showProp("microedition.http_proxy")); props.addCommand(exitCommand); props.setCommandListener(this); display.setCurrent(props); }