List of usage examples for java.lang System runFinalization
public static void runFinalization()
From source file:org.archive.modules.seeds.TextSeedModule.java
/** * Announce all seeds (and nonseed possible-directive lines) from * the given Reader/*from w ww . ja va 2s.co m*/ * @param reader source of seed/directive lines * @param latchOrNull if non-null, sent countDown after each line, allowing * another thread to proceed after a configurable number of lines processed */ protected void announceSeedsFromReader(BufferedReader reader, CountDownLatch latchOrNull) { String s; Iterator<String> iter = new RegexLineIterator(new LineReadingIterator(reader), RegexLineIterator.COMMENT_LINE, RegexLineIterator.NONWHITESPACE_ENTRY_TRAILING_COMMENT, RegexLineIterator.ENTRY); int count = 0; while (iter.hasNext()) { s = (String) iter.next(); if (Character.isLetterOrDigit(s.charAt(0))) { // consider a likely URI seedLine(s); count++; if (count % 20000 == 0) { System.runFinalization(); } } else { // report just in case it's a useful directive nonseedLine(s); } if (latchOrNull != null) { latchOrNull.countDown(); } } publishConcludedSeedBatch(); }
From source file:org.apache.mnemonic.Utils.java
/** * run a garbage collection.//from www. j a va 2s .co m * * @param timeout * specify a timeout for this operation * */ public static void collectGarbage(long timeout) { try { System.gc(); Thread.sleep(timeout); System.runFinalization(); Thread.sleep(timeout); } catch (InterruptedException ex) { ex.printStackTrace(); } }
From source file:com.google.gdt.eclipse.designer.ie.jsni.ModuleSpaceIE6.java
@Override public void dispose() { for (NativeFunctionInfo function : m_nativeFunctions.values()) { function.dispose();/*from w w w .j a v a 2 s. c om*/ } // Dispose everything else. if (window != null) { window.dispose(); } super.dispose(); IDispatchProxy.clearIDispatchProxyRefs(getIsolatedClassLoader()); for (int i = 0; i < 2; i++) { if (!GWTEnvironmentUtils.DEVELOPERS_HOST) { System.gc(); } System.runFinalization(); JsValue.mainThreadCleanup(); } }
From source file:org.xwoot.xwootApp.core.XWootPage.java
public synchronized void unloadPage(String lastVuePagesDir) throws XWootException { this.storePage(lastVuePagesDir); System.runFinalization(); System.gc();/*from w ww. j a v a 2s.c o m*/ }
From source file:org.kiji.schema.cassandra.CassandraKijiClientTest.java
/** * Closes the in-memory kiji instance.// w w w.j av a2s . co m * @throws Exception If there is an error. */ @After public final void tearDownKijiTest() throws Exception { LOG.debug("Tearing down {}", mTestId); for (Kiji kiji : mAllKijis) { kiji.release(); CassandraKijiInstaller.get().uninstall(kiji.getURI(), null); } mAllKijis = null; mKiji = null; FileUtils.deleteDirectory(mLocalTempDir); mLocalTempDir = null; mTestId = null; // Force a garbage collection, to trigger finalization of resources and spot // resources that were not released or closed. System.gc(); System.runFinalization(); }
From source file:org.geogig.geoserver.functional.GeoServerFunctionalTestContext.java
/** * Clean up resources used in the scenario. */// www . j ava 2 s .co m @Override protected void tearDown() throws Exception { try { if (helper != null) { RepositoryManager.close(); helper.doTearDown(); } if (testData != null) { testData.tearDown(); } } finally { helper = null; } System.runFinalization(); }
From source file:it.geosolutions.tools.io.file.FileRemover.java
/** * This method does the magic:// w w w.j a v a 2 s.c o m * * <ol> * <li>iterate over all the files</li> * <li>try to delete it</li> * <li>if successful drop the file references</li> * <li>if not successful increase the attempts count for the file and call * the gc. If the maximum number was exceeded drop the file and warn the * user</li> * */ public void run() { while (true) { try { synchronized (FILES_PATH) { synchronized (FILE_ATTEMPTS_COUNTS) { final Iterator<String> it = FILES_PATH.iterator(); while (it.hasNext()) { // get next file path and its count final String sFile = it.next(); if (LOGGER.isInfoEnabled()) LOGGER.info("Trying to remove file " + sFile); int attempts = FILE_ATTEMPTS_COUNTS.get(sFile).intValue(); if (!new File(sFile).exists()) { it.remove(); FILE_ATTEMPTS_COUNTS.remove(sFile); } else { // try to delete it if (new File(sFile).delete()) { if (LOGGER.isInfoEnabled()) LOGGER.info("Successfully removed file " + sFile); it.remove(); FILE_ATTEMPTS_COUNTS.remove(sFile); } else { if (LOGGER.isInfoEnabled()) LOGGER.info("Unable to remove file " + sFile); attempts++; if (maxAttempts < attempts) { if (LOGGER.isInfoEnabled()) LOGGER.info("Dropping file " + sFile); it.remove(); FILE_ATTEMPTS_COUNTS.remove(sFile); if (LOGGER.isWarnEnabled()) LOGGER.warn("Unable to delete file " + sFile); } else { FILE_ATTEMPTS_COUNTS.remove(sFile); FILE_ATTEMPTS_COUNTS.put(sFile, new Integer(attempts)); // might help, see // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4715154 Runtime.getRuntime().gc(); Runtime.getRuntime().gc(); Runtime.getRuntime().gc(); Runtime.getRuntime().gc(); Runtime.getRuntime().gc(); Runtime.getRuntime().gc(); System.runFinalization(); System.runFinalization(); System.runFinalization(); System.runFinalization(); System.runFinalization(); System.runFinalization(); } } } } } } Thread.sleep(period * 1000); } catch (Throwable t) { if (LOGGER.isInfoEnabled()) LOGGER.info(t.getLocalizedMessage(), t); } } }
From source file:org.archive.io.GenericReplayCharSequence.java
/** * Converts the first <code>Integer.MAX_VALUE</code> characters from the * file <code>backingFilename</code> from encoding <code>encoding</code> to * encoding <code>WRITE_ENCODING</code> and saves as * <code>this.decodedFile</code>, which is named <code>backingFilename * + "." + WRITE_ENCODING</code>.//w ww. j a va2s . c om * * @throws IOException */ protected void decode(InputStream inStream, int prefixMax, String backingFilename, Charset charset) throws IOException { this.charset = charset; // TODO: consider if BufferedReader is helping any // TODO: consider adding TBW 'LimitReader' to stop reading at // Integer.MAX_VALUE characters because of charAt(int) limit BufferedReader reader = new BufferedReader(new InputStreamReader(inStream, charset)); logger.fine("backingFilename=" + backingFilename + " encoding=" + charset + " decodedFile=" + decodedFile); this.prefixBuffer = CharBuffer.allocate(prefixMax); long count = 0; while (count < prefixMax) { int read = reader.read(prefixBuffer); if (read < 0) { break; } count += read; } int ch = reader.read(); if (ch >= 0) { count++; // more to decode to file overflow this.decodedFile = new File(backingFilename + "." + WRITE_ENCODING); FileOutputStream fos; try { fos = new FileOutputStream(this.decodedFile); } catch (FileNotFoundException e) { // Windows workaround attempt System.gc(); System.runFinalization(); this.decodedFile = new File(decodedFile.getAbsolutePath() + ".win"); logger.info("Windows 'file with a user-mapped section open' " + "workaround gc/finalization/name-extension performed."); // try again fos = new FileOutputStream(this.decodedFile); } Writer writer = new OutputStreamWriter(fos, WRITE_ENCODING); writer.write(ch); count += IOUtils.copyLarge(reader, writer); writer.close(); reader.close(); } this.length = Ints.saturatedCast(count); if (count > Integer.MAX_VALUE) { logger.warning("input stream is longer than Integer.MAX_VALUE=" + NumberFormat.getInstance().format(Integer.MAX_VALUE) + " characters -- only first " + NumberFormat.getInstance().format(Integer.MAX_VALUE) + " are accessible through this GenericReplayCharSequence"); } logger.fine("decode: decoded " + count + " characters" + ((decodedFile == null) ? "" : " (" + (count - prefixBuffer.length()) + " to " + decodedFile + ")")); }
From source file:net.sqs2.omr.app.MarkReaderControllerImpl.java
public void userExit() { Window window = RemoteWindowDecorator.inactivate(getNetworkPeer().getRMIPort()); window.setVisible(false);/*ww w . jav a 2 s . co m*/ try { SQSHttpdManager.getEXIgridHttpd().stop(); } catch (Exception ignore) { ignore.printStackTrace(); } userShutdown(); System.runFinalization(); System.exit(0); }