Example usage for java.lang System gc

List of usage examples for java.lang System gc

Introduction

In this page you can find the example usage for java.lang System gc.

Prototype

public static void gc() 

Source Link

Document

Runs the garbage collector in the Java Virtual Machine.

Usage

From source file:net.sf.ehcache.jcache.JCacheTest.java

/**
 * setup test/*w ww .j a va  2 s. c o  m*/
 */
protected void setUp() throws Exception {
    super.setUp();
    System.gc();
    Thread.sleep(100);
    System.gc();
}

From source file:org.jahia.modules.serversettings.memoryThread.MemoryThreadInformationManagement.java

public void doGarbageCollection(MessageContext messages) {
    System.gc();
    messages.addMessage(/*from  w  ww .  j  a v  a  2s .  c  o  m*/
            new MessageBuilder().info().code("serverSettings.manageMemory.memory.gc.triggered").build());
}

From source file:IntegrationTests.FileStorageUploadIT.java

@After
public void tearDown() throws StorageException {
    System.gc();
    Iterator it = testEnv.uploadFileList.entrySet().iterator();
    if (it.hasNext()) {
        Map.Entry pair = (Map.Entry) it.next();
        File x = (File) pair.getValue();
        LOGGER.log(Level.INFO, x.getParent() + " will now be deleted");
        try {//ww w . ja v  a  2  s  .com
            FileUtils.deleteDirectory(x.getParentFile());
        } catch (IOException ex) {
            Logger.getLogger(WAStorageClientUploadIT.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    testEnv.fileShare.deleteIfExists();
    testEnv.uploadFileList.clear();
}

From source file:com.duroty.application.files.manager.SendMessageThread.java

/**
 * <p>/*w w  w. j av a 2  s.  co m*/
 * Implementation of Thread.run()
 * </p>
 */
public void start() throws Exception {
    try {
        if (email != null) {
            email.getMimeMessage().removeHeader("X-DBox");
            email.send();

            return;
        }

        if (mime != null) {
            mime.removeHeader("X-DBox");
            Transport.send(mime);

            return;
        }

        if (mimes != null) {
            for (int i = 0; i < mimes.size(); i++) {
                MimeMessage mm = (MimeMessage) mimes.get(i);
                mm.removeHeader("X-DBox");
                Transport.send(mm);
            }
        }
    } catch (Exception ex) {
        throw new MailException(ex);
    } catch (java.lang.OutOfMemoryError ex) {
        System.gc();
        throw new MailException(ex);
    } catch (Throwable ex) {
        throw new MailException(ex);
    } finally {
        System.gc();
    }
}

From source file:edu.ehu.galan.lite.algorithms.ranked.supervised.tfidf.corpus.wikipedia.WikiCorpusBuilder.java

/**
 *
 * @param pIndexDir/*from   ww  w .  j  ava2s  . c  o  m*/
 * @param wikiExtractorDir
 * @param wordsLimit
 */
public void buildIndex(String pIndexDir, String wikiExtractorDir, int wordsLimit) {
    limit = wordsLimit;
    initializeIndex(pIndexDir);
    extract(new File(wikiExtractorDir));
    System.gc();
}

From source file:ms1quant.MS1TargetQuantThread.java

@Override
public void run() {
    try {/*from www .  j a  va 2s  .c  om*/

        Logger.getRootLogger().info("Processing file " + mzxmlfile.getAbsolutePath() + "....");

        long time = System.currentTimeMillis();
        LCMSPeakMS1 LCMS1 = new LCMSPeakMS1(mzxmlfile.getAbsolutePath(), NoCPUs);
        LCMS1.SetParameter(param);

        LCMS1.Resume = false;
        if (!param.TargetIDOnly) {
            LCMS1.CreatePeakFolder();
        }
        LCMS1.ExportPeakClusterTable = false;

        if (id.PSMList.isEmpty()) {
            Logger.getRootLogger()
                    .warn("There is no PSM mapped to the file:" + mzxmlfile.getName() + ", skipping the file.");
            return;
        }
        LCMS1.IDsummary = id;
        LCMS1.IDsummary.mzXMLFileName = mzxmlfile.getAbsolutePath();

        if (param.TargetIDOnly) {
            LCMS1.SaveSerializationFile = false;
        }

        if (param.TargetIDOnly || !LCMS1.ReadPeakCluster()) {
            LCMS1.PeakClusterDetection();
        }

        LCMS1.AssignQuant(false);
        LCMS1.IDsummary.ExportPepID(outputfolder);

        time = System.currentTimeMillis() - time;
        //logger.info(LCMS1.ParentmzXMLName + " processed time:" + String.format("%d hour, %d min, %d sec", TimeUnit.MILLISECONDS.toHours(time), TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)), TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))));
        Logger.getRootLogger()
                .info(LCMS1.ParentmzXMLName + " processed time:"
                        + String.format("%d hour, %d min, %d sec", TimeUnit.MILLISECONDS.toHours(time),
                                TimeUnit.MILLISECONDS.toMinutes(time)
                                        - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)),
                                TimeUnit.MILLISECONDS.toSeconds(time)
                                        - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))));
        LCMS1.BaseClearAllPeaks();
        LCMS1.SetSpectrumParser(null);
        LCMS1.IDsummary = null;
        LCMS1 = null;
        id.ReleaseIDs();
        id = null;
        System.gc();
    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
    }
}

From source file:edu.rit.flick.util.FlickTest.java

@After
public void cleanUpTempFiles() throws InterruptedException {
    System.gc();
    Thread.sleep(100);//from w  w w . j  a  va2 s  .  c om

    if (flickedFile != null && flickedFile.exists())
        assertTrue(FileUtils.deleteQuietly(flickedFile));
    if (unflickedFile != null && unflickedFile.exists())
        assertTrue(FileUtils.deleteQuietly(unflickedFile));
}

From source file:ch.sourcepond.io.checksum.impl.PathUpdateStrategyTest.java

/**
 * //from ww w . j  a  v a 2 s .c  o  m
 */
@Test(timeout = 2000)
public void verifyUpdateDigestGCRun() throws Exception {
    strategy = newStrategy(SHA256, realFile);
    final long objectIdentityBeforeGC = System.identityHashCode(strategy.getTempBuffer());

    // Call to update will set the hard-reference tempBuffer to null. This
    // is necessary, otherwise the weak-reference will not be cleared.
    strategy.update(0, MILLISECONDS);

    // After running the garbage collector the weak-references should have
    // been cleared.
    System.gc();
    assertNotEquals(objectIdentityBeforeGC, System.identityHashCode(strategy.getTempBuffer()));
}

From source file:org.mythdroid.services.JSONClient.java

/**
 * Perform a GET request of the specified path
 * @param path relative path of the query
 * @param query HashMap of query parameters
 * @return a JSONObject with the results
 * @throws IOException /* w w  w .  j a va 2 s.  co m*/
 */
public JSONObject Get(String path, Params query) throws IOException {
    try {
        return Request(new HttpGet(CreateURI(path, query)));
    } catch (URISyntaxException e) {
        ErrUtil.logErr(e);
        ErrUtil.report(e);
        throw new IOException(e.getMessage());
    } catch (IllegalStateException e) {
        ErrUtil.logErr(e);
        ErrUtil.report(e);
        throw new IOException(e.getMessage());
    } catch (OutOfMemoryError e) {
        System.gc();
        ErrUtil.logErr(e.getMessage());
        ErrUtil.report(e.getMessage());
        throw new IOException(e.getMessage());
    }
}

From source file:com.orange.clara.cloud.servicedbdumper.filer.s3uploader.UploadS3StreamImpl.java

@Override
public String upload(InputStream content, Blob blob) throws IOException {
    String key = blob.getMetadata().getName();
    String bucketName = this.blobStoreContext.getBucketName();
    ContentMetadata metadata = blob.getMetadata().getContentMetadata();
    ObjectMetadataBuilder builder = ObjectMetadataBuilder.create().key(key)
            .contentType(MediaType.OCTET_STREAM.toString()).contentDisposition(key)
            .contentEncoding(metadata.getContentEncoding()).contentLanguage(metadata.getContentLanguage())
            .userMetadata(blob.getMetadata().getUserMetadata());
    String uploadId = this.s3Client.initiateMultipartUpload(bucketName, builder.build());
    Integer partNum = 1;//from  w  ww. jav  a2  s  .c o m
    Payload part = null;
    int bytesRead = 0;
    byte[] chunk = null;
    boolean shouldContinue = true;
    SortedMap<Integer, String> etags = Maps.newTreeMap();
    try {
        while (shouldContinue) {
            chunk = new byte[chunkSize];
            bytesRead = ByteStreams.read(content, chunk, 0, chunk.length);
            if (bytesRead != chunk.length) {
                shouldContinue = false;
                chunk = Arrays.copyOf(chunk, bytesRead);
                if (chunk.length == 0) {
                    //something from jvm causing memory leak, we try to help jvm which seems working.
                    //but PLEASE DON'T REPLICATE AT HOME !
                    chunk = null;
                    part = null;
                    System.gc();
                    //
                    break;
                }
            }
            part = new ByteArrayPayload(chunk);
            prepareUploadPart(bucketName, key, uploadId, partNum, part, etags);
            partNum++;
            //something from jvm causing memory leak, we try to help jvm which seems working.
            //but PLEASE DON'T REPLICATE AT HOME !
            chunk = null;
            part = null;
            System.gc();
            //
        }
        return this.completeMultipartUpload(bucketName, key, uploadId, etags);
    } catch (RuntimeException ex) {
        this.s3Client.abortMultipartUpload(bucketName, key, uploadId);
        throw ex;
    }
}