List of usage examples for java.lang System runFinalization
public static void runFinalization()
From source file:CollectionTest.java
static void cleanGC() { System.gc(); System.runFinalization(); System.gc(); }
From source file:MemoryUtils.java
public static void freeMemory() { System.gc(); System.runFinalization(); }
From source file:com.extradea.framework.images.cache.LruBitmapCache.java
@Override public void clear() { imageCache.evictAll(); System.gc(); System.runFinalization(); System.gc(); System.gc(); }
From source file:heigit.ors.servlet.listeners.ORSInitContextListener.java
public void contextDestroyed(ServletContextEvent contextEvent) { try {/*from www. j a v a2s. co m*/ LOGGER.info("Start shutting down ORS and releasing resources."); if (RoutingProfileManagerStatus.isReady()) RoutingProfileManager.getInstance().destroy(); StatisticsProviderFactory.releaseProviders(); LogFactory.release(Thread.currentThread().getContextClassLoader()); try { System.gc(); System.runFinalization(); System.gc(); System.runFinalization(); } catch (Throwable t) { LOGGER.error("Failed to perform finalization."); t.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:gov.nih.nci.cabig.caaers.CaaersTestCase.java
@Override protected void tearDown() throws Exception { super.tearDown(); tearDownTestAuthorization();/*from ww w . j av a 2 s . c o m*/ tearDownAuditing(); System.runFinalization(); }
From source file:CreateTest.java
public static void cleanGC() { System.gc(); System.runFinalization(); System.gc(); }
From source file:VASSAL.tools.io.TempFileManager.java
private TempFileManager() { ////from w w w .j ava2 s .c o m // set up for cleanup on shutdown // if (SystemUtils.IS_OS_WINDOWS) { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { // Run the garbage collector and finalize repeatedly, with // exponentially increasing pauses, until we succeed at deleting // the whole session temp directory or we hit the sleep limit. long sleep = 1; final long maxsleep = 1024; while (true) { System.gc(); System.runFinalization(); try { cleanupSessionRoot(); break; } catch (IOException e) { if (sleep > maxsleep) { // just log, since shutdown hooks don't have long to run logger.error("", e); break; } try { Thread.sleep(sleep); } catch (InterruptedException ignore) { } sleep *= 2; } } } }); } else { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { cleanupSessionRoot(); } catch (IOException e) { // just log, since shutdown hooks don't have long to run logger.error("", e); } } }); } tmpRoot = Info.getTempDir(); // // clean up stale temporary files // if (tmpRoot.exists() && tmpRoot.isDirectory()) { final FileFilter filter = new FileFilter() { public boolean accept(File f) { return f.isDirectory() && f.getName().startsWith(DIR_PREFIX); } }; for (File f : tmpRoot.listFiles(filter)) { final File lock = new File(f.getParent(), f.getName() + ".lck"); if (!lock.exists()) { try { FileUtils.forceDelete(f); } catch (IOException e) { logger.error("", e); } } } } }
From source file:LowMemory.java
/** * Set a low memory watermark where the owner of this object just hit an * OutOfMemoryError. The caller is assumed it has just freed up any * references it obtained during the operation, so that the freeMemory call * as best as it can reflects the memory before the action that caused the * OutOfMemoryError, not part way through the action. * //w w w . j a v a 2 s . c o m */ public void setLowMemory() { // Can read lowMemory unsynchronized, worst // case is that we force extra garbage collection. if (lowMemory == 0L) { // The caller tried to dereference any objects it // created during its instantation. Try to garbage // collect these so that we can a best-guess effort // at the free memory before the overall operation we are // failing on occurred. Of course in active multi-threading // systems we run the risk that some other thread just freed // up some memory that throws off our calcuation. This is // avoided by clearing lowMemory some time later on an // isLowMemory() call. for (int i = 0; i < 5; i++) { System.gc(); System.runFinalization(); try { Thread.sleep(50L); } catch (InterruptedException e) { } } } synchronized (this) { if (lowMemory == 0L) { lowMemory = Runtime.getRuntime().freeMemory(); whenLowMemorySet = System.currentTimeMillis(); } } }
From source file:com.enioka.jqm.tools.BasicTest.java
@After public void after() { jqmlogger.debug("********* TEST CLEANUP"); engine1.stop();//from w w w . j a v a2 s . c o m em.close(); JqmClientFactory.resetClient(); System.runFinalization(); System.gc(); System.runFinalization(); System.gc(); System.gc(); }
From source file:org.sakaiproject.kernel.component.KernelLifecycle.java
/** * Execute the start phase of the lifecycle, creating the MBean and registering the newly started * Kernel with JMX.//w w w .java2 s . c om * * @see org.sakaiproject.kernel.loader.common.CommonLifecycle#start() */ public void start() { LOG.info("==========PHASE 1 STARTING ================="); try { long start = System.currentTimeMillis(); lifecycleEvent(CommonLifecycleEvent.BEFORE_START); lastLoadDate = new Date(); // Start the kernel MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); RequiredModelMBean model = new RequiredModelMBean(createMBeanInfo()); model.setManagedResource(this, "objectReference"); ObjectName kernelName = new ObjectName(Kernel.MBEAN_KERNEL); mbs.registerMBean(model, kernelName); kernel = new KernelImpl(); kernel.start(); // Start the service manager serviceManager = new ServiceManagerImpl(kernel); serviceManager.start(); // Start the component manager. componentManager = new ComponentManagerImpl(kernel); componentManager.start(); try { System.runFinalization(); Runtime.getRuntime().gc(); CompositeData permGen = null; try { permGen = (CompositeData) mbs .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=Perm Gen"), "Usage"); } catch (Exception ex) { permGen = (CompositeData) mbs .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=CMS Perm Gen"), "Usage"); } CompositeData tenuredGen; try { tenuredGen = (CompositeData) mbs .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=Tenured Gen"), "Usage"); } catch (Exception ex) { tenuredGen = (CompositeData) mbs .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=CMS Old Gen"), "Usage"); } CompositeData codeCache = (CompositeData) mbs .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=Code Cache"), "Usage"); CompositeData edenSpace = null; try { edenSpace = (CompositeData) mbs .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=Eden Space"), "Usage"); } catch (Exception ex) { edenSpace = (CompositeData) mbs .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=Par Eden Space"), "Usage"); } CompositeData survivorSpace = null; try { survivorSpace = (CompositeData) mbs .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=Survivor Space"), "Usage"); } catch (Exception ex) { survivorSpace = (CompositeData) mbs.getAttribute( new ObjectName("java.lang:type=MemoryPool,name=Par Survivor Space"), "Usage"); } long permGenUsed = Long.parseLong(String.valueOf(permGen.get("used"))); long codeCacheUsed = Long.parseLong(String.valueOf(codeCache.get("used"))); long edenSpaceUsed = Long.parseLong(String.valueOf(edenSpace.get("used"))); long tenuredGenUsed = Long.parseLong(String.valueOf(tenuredGen.get("used"))); long survivorSpaceUsed = Long.parseLong(String.valueOf(survivorSpace.get("used"))); LOG.info("Memory Stats after startup\n" + "\tPermgen Used " + permGenUsed / (ONEM) + " MB\n" + "\tCode Cache Used " + codeCacheUsed / (ONEM) + " MB\n" + "\tEden Used " + edenSpaceUsed / (ONEM) + " MB\n" + "\tTenured Used " + tenuredGenUsed / (ONEM) + " MB\n" + "\tSurvivour Used " + survivorSpaceUsed / (ONEM) + " MB"); } catch (RuntimeException ex2) { LOG.info("Startup Memory Stats Not available ", ex2); } catch (Exception ex2) { LOG.info("Startup Memory Stats Not available ", ex2); } lifecycleEvent(CommonLifecycleEvent.START); lifecycleEvent(CommonLifecycleEvent.AFTER_START); loadTime = System.currentTimeMillis() - start; } catch (Throwable ex) { LOG.error("Failed to start Component Lifecycle ", ex); throw new Error("Failed to start Component Lifecycle ", ex); } LOG.info("============END of LIFECYCLE STARTUP==============================="); }