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:io.realm.datastorebenchmark.DataStoreTest.java

protected void tearDown() {
    System.gc();
}

From source file:me.aerovulpe.crawler.ui.GifImageView.java

private void playGif() {
    try {/*from www .  ja va 2 s .c  om*/
        mGifThread.start();
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
        System.gc();
    }
}

From source file:hudson.remoting.RegExpBenchmark.java

@Test
public void benchmark() throws Exception {
    System.out.println("there are " + getAllRTClasses().size());

    List<String> classes = getAllRTClasses();
    final long startRegExp = System.nanoTime();
    final List<String> matchesRegExp = checkClassesRegExp(classes);
    final long durationRegexpNanos = System.nanoTime() - startRegExp;
    classes = null;/*from ww w.  jav  a  2 s  .c  om*/

    System.gc();
    System.gc();
    System.gc();

    // make sure we use new Strings each time so that hotpsot does not do funky caching (after all the strings we will be testing will come from the stream and be new).
    classes = getAllRTClasses();
    final long startSingleRegExp = System.nanoTime();
    final List<String> matchesSingleRegExp = checkClassesSingleRegExp(classes);
    final long durationSingleRegexpNanos = System.nanoTime() - startSingleRegExp;
    classes = null;
    System.gc();
    System.gc();
    System.gc();

    // make sure we use new Strings each time so that hotpsot does not do funky caching (after all the strings we will be testing will come from the stream and be new).
    classes = getAllRTClasses();
    final long startString = System.nanoTime();
    final List<String> matchesString = checkClassesString(classes);
    final long durationStringNanos = System.nanoTime() - startString;

    System.out.println(String.format(Locale.ENGLISH,
            "%-13s: %d blacklisted classes in %9dns.  Average class check time is %dns",
            new Object[] { "RegExp ", matchesRegExp.size(), durationRegexpNanos,
                    durationRegexpNanos / classes.size() }));
    System.out.println(String.format(Locale.ENGLISH,
            "%-13s: %d blacklisted classes in %9dns.  Average class check time is %dns",
            new Object[] { "SingleRegExp ", matchesSingleRegExp.size(), durationSingleRegexpNanos,
                    durationSingleRegexpNanos / classes.size() }));
    System.out.println(String.format(Locale.ENGLISH,
            "%-13s: %d blacklisted classes in %9dns.  Average class check time is %dns",
            new Object[] { "String ", matchesString.size(), durationStringNanos,
                    durationStringNanos / classes.size() }));

    System.out.println("Regular Expression is " + durationRegexpNanos / durationStringNanos + " times slower");
    System.out.println("Single Regular Expression is " + durationSingleRegexpNanos / durationStringNanos
            + " times slower\n");
}

From source file:CreateTest.java

public static void cleanGC() {
    System.gc();
    System.runFinalization();
    System.gc();
}

From source file:de.hybris.platform.cache.CachePerformanceTest.java

@After
public void clean() {
    CacheManager.getInstance().clearAll();
    System.gc();
}

From source file:DIA_Umpire_Quant.DIA_Umpire_IntLibSearch.java

/**
 * @param args the command line arguments
 *//*from www .  j  a  v a2s . co  m*/
public static void main(String[] args) throws FileNotFoundException, IOException, Exception {
    System.out.println(
            "=================================================================================================");
    System.out.println("DIA-Umpire targeted re-extraction analysis using internal library (version: "
            + UmpireInfo.GetInstance().Version + ")");
    if (args.length != 1) {
        System.out.println(
                "command format error, the correct format should be : java -jar -Xmx10G DIA_Umpire_IntLibSearch.jar diaumpire_module.params");
        return;
    }
    try {
        ConsoleLogger.SetConsoleLogger(Level.INFO);
        ConsoleLogger.SetFileLogger(Level.DEBUG,
                FilenameUtils.getFullPath(args[0]) + "diaumpire_intlibsearch.log");
    } catch (Exception e) {
    }

    Logger.getRootLogger().info("Version: " + UmpireInfo.GetInstance().Version);
    Logger.getRootLogger().info("Parameter file:" + args[0]);

    BufferedReader reader = new BufferedReader(new FileReader(args[0]));
    String line = "";
    String WorkFolder = "";
    int NoCPUs = 2;

    String InternalLibID = "";

    float ProbThreshold = 0.99f;
    float RTWindow_Int = -1f;
    float Freq = 0f;
    int TopNFrag = 6;

    TandemParam tandemPara = new TandemParam(DBSearchParam.SearchInstrumentType.TOF5600);
    HashMap<String, File> AssignFiles = new HashMap<>();

    //<editor-fold defaultstate="collapsed" desc="Reading parameter file">
    while ((line = reader.readLine()) != null) {
        line = line.trim();
        Logger.getRootLogger().info(line);
        if (!"".equals(line) && !line.startsWith("#")) {
            //System.out.println(line);
            if (line.equals("==File list begin")) {
                do {
                    line = reader.readLine();
                    line = line.trim();
                    if (line.equals("==File list end")) {
                        continue;
                    } else if (!"".equals(line)) {
                        File newfile = new File(line);
                        if (newfile.exists()) {
                            AssignFiles.put(newfile.getAbsolutePath(), newfile);
                        } else {
                            Logger.getRootLogger().info("File: " + newfile + " does not exist.");
                        }
                    }
                } while (!line.equals("==File list end"));
            }
            if (line.split("=").length < 2) {
                continue;
            }
            String type = line.split("=")[0].trim();
            String value = line.split("=")[1].trim();
            switch (type) {
            case "Path": {
                WorkFolder = value;
                break;
            }
            case "path": {
                WorkFolder = value;
                break;
            }
            case "Thread": {
                NoCPUs = Integer.parseInt(value);
                break;
            }

            case "InternalLibID": {
                InternalLibID = value;
                break;
            }

            case "RTWindow_Int": {
                RTWindow_Int = Float.parseFloat(value);
                break;
            }

            case "ProbThreshold": {
                ProbThreshold = Float.parseFloat(value);
                break;
            }
            case "TopNFrag": {
                TopNFrag = Integer.parseInt(value);
                break;
            }
            case "Freq": {
                Freq = Float.parseFloat(value);
                break;
            }
            case "Fasta": {
                tandemPara.FastaPath = value;
                break;
            }
            }
        }
    }
    //</editor-fold>

    //Initialize PTM manager using compomics library
    PTMManager.GetInstance();

    //Check if the fasta file can be found
    if (!new File(tandemPara.FastaPath).exists()) {
        Logger.getRootLogger().info("Fasta file :" + tandemPara.FastaPath
                + " cannot be found, the process will be terminated, please check.");
        System.exit(1);
    }

    //Generate DIA file list
    ArrayList<DIAPack> FileList = new ArrayList<>();
    try {
        File folder = new File(WorkFolder);
        if (!folder.exists()) {
            Logger.getRootLogger().info("The path : " + WorkFolder + " cannot be found.");
            System.exit(1);
        }
        for (final File fileEntry : folder.listFiles()) {
            if (fileEntry.isFile()
                    && (fileEntry.getAbsolutePath().toLowerCase().endsWith(".mzxml")
                            | fileEntry.getAbsolutePath().toLowerCase().endsWith(".mzml"))
                    && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q1.mzxml")
                    && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q2.mzxml")
                    && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q3.mzxml")) {
                AssignFiles.put(fileEntry.getAbsolutePath(), fileEntry);
            }
            if (fileEntry.isDirectory()) {
                for (final File fileEntry2 : fileEntry.listFiles()) {
                    if (fileEntry2.isFile()
                            && (fileEntry2.getAbsolutePath().toLowerCase().endsWith(".mzxml")
                                    | fileEntry2.getAbsolutePath().toLowerCase().endsWith(".mzml"))
                            && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q1.mzxml")
                            && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q2.mzxml")
                            && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q3.mzxml")) {
                        AssignFiles.put(fileEntry2.getAbsolutePath(), fileEntry2);
                    }
                }
            }
        }

        Logger.getRootLogger().info("No. of files assigned :" + AssignFiles.size());
        for (File fileEntry : AssignFiles.values()) {
            Logger.getRootLogger().info(fileEntry.getAbsolutePath());
        }
        for (File fileEntry : AssignFiles.values()) {
            String mzXMLFile = fileEntry.getAbsolutePath();
            if (mzXMLFile.toLowerCase().endsWith(".mzxml") | mzXMLFile.toLowerCase().endsWith(".mzml")) {
                DIAPack DiaFile = new DIAPack(mzXMLFile, NoCPUs);
                Logger.getRootLogger().info(
                        "=================================================================================================");
                Logger.getRootLogger().info("Processing " + mzXMLFile);
                if (!DiaFile.LoadDIASetting()) {
                    Logger.getRootLogger().info("Loading DIA setting failed, job is incomplete");
                    System.exit(1);
                }
                if (!DiaFile.LoadParams()) {
                    Logger.getRootLogger().info("Loading parameters failed, job is incomplete");
                    System.exit(1);
                }
                Logger.getRootLogger().info("Loading identification results " + mzXMLFile + "....");

                //If the serialization file for ID file existed
                if (DiaFile.ReadSerializedLCMSID()) {
                    DiaFile.IDsummary.ReduceMemoryUsage();
                    DiaFile.IDsummary.FastaPath = tandemPara.FastaPath;
                    FileList.add(DiaFile);
                }
            }
        }

        //<editor-fold defaultstate="collapsed" desc="Targete re-extraction using internal library">            
        Logger.getRootLogger().info(
                "=================================================================================================");
        if (FileList.size() > 1) {
            Logger.getRootLogger().info("Targeted re-extraction using internal library");

            FragmentLibManager libManager = FragmentLibManager.ReadFragmentLibSerialization(WorkFolder,
                    InternalLibID);
            if (libManager == null) {
                Logger.getRootLogger().info("Building internal spectral library");
                libManager = new FragmentLibManager(InternalLibID);
                ArrayList<LCMSID> LCMSIDList = new ArrayList<>();
                for (DIAPack dia : FileList) {
                    LCMSIDList.add(dia.IDsummary);
                }
                libManager.ImportFragLibTopFrag(LCMSIDList, Freq, TopNFrag);
                libManager.WriteFragmentLibSerialization(WorkFolder);
            }
            libManager.ReduceMemoryUsage();

            Logger.getRootLogger()
                    .info("Building retention time prediction model and generate candidate peptide list");
            for (int i = 0; i < FileList.size(); i++) {
                FileList.get(i).IDsummary.ClearMappedPep();
            }
            for (int i = 0; i < FileList.size(); i++) {
                for (int j = i + 1; j < FileList.size(); j++) {
                    RTAlignedPepIonMapping alignment = new RTAlignedPepIonMapping(WorkFolder,
                            FileList.get(i).GetParameter(), FileList.get(i).IDsummary,
                            FileList.get(j).IDsummary);
                    alignment.GenerateModel();
                    alignment.GenerateMappedPepIon();
                }
                FileList.get(i).ExportID();
                FileList.get(i).IDsummary = null;
            }

            Logger.getRootLogger().info("Targeted matching........");
            for (DIAPack diafile : FileList) {
                if (diafile.IDsummary == null) {
                    diafile.ReadSerializedLCMSID();
                }
                if (!diafile.IDsummary.GetMappedPepIonList().isEmpty()) {
                    diafile.UseMappedIon = true;
                    diafile.FilterMappedIonByProb = false;
                    diafile.BuildStructure();
                    diafile.MS1FeatureMap.ReadPeakCluster();
                    diafile.MS1FeatureMap.ClearMonoisotopicPeakOfCluster();
                    diafile.GenerateMassCalibrationRTMap();
                    diafile.TargetedExtractionQuant(false, libManager, ProbThreshold, RTWindow_Int);
                    diafile.MS1FeatureMap.ClearAllPeaks();
                    diafile.IDsummary.ReduceMemoryUsage();
                    diafile.IDsummary.RemoveLowProbMappedIon(ProbThreshold);
                    diafile.ExportID();
                    Logger.getRootLogger().info("Peptide ions: " + diafile.IDsummary.GetPepIonList().size()
                            + " Mapped ions: " + diafile.IDsummary.GetMappedPepIonList().size());
                    diafile.ClearStructure();
                }
                diafile.IDsummary = null;
                System.gc();
            }
            Logger.getRootLogger().info(
                    "=================================================================================================");
        }
        //</editor-fold>

        Logger.getRootLogger().info("Job done");
        Logger.getRootLogger().info(
                "=================================================================================================");

    } catch (Exception e) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(e));
        throw e;
    }
}

From source file:com.netflix.zeno.fastblob.state.WeakObjectOrdinalMapTest.java

private void doGC() throws InterruptedException {
    System.gc();
    Thread.sleep(1000);
}

From source file:com.surevine.alfresco.audit.MultiReadHttpServletRequestTest.java

MultiReadHttpServletRequest testRequestWithSize(int size) throws Exception {
    MockHttpServletRequest mockRequest = new MockHttpServletRequest();

    byte[] testData = getTestData(size);

    mockRequest.setContent(testData); // A request

    MultiReadHttpServletRequest request = new MultiReadHttpServletRequest(mockRequest);

    byte[] result1 = IOUtils.toByteArray(request.getInputStream());
    assertTrue("result1 should equal the input array. [" + testData.length + ", " + result1.length + "]",
            Arrays.equals(testData, result1));

    result1 = null;/*from w ww . j  a v  a 2s. c o m*/
    System.gc();

    byte[] result2 = IOUtils.toByteArray(request.getInputStream());
    assertTrue("result2 should equal the output array [" + testData.length + ", " + result2.length + "]",
            Arrays.equals(testData, result2));

    testData = null;
    result2 = null;
    System.gc();

    return request;
}

From source file:es.udc.gii.rosamituscma.ConstrainedMotionEvolutionaryAlgorithm.java

@Override
protected synchronized void reproduce(Population population) {
    //        super.reproduce(population);

    while (buffer_population.size() < this.getPopulation().getSize()) {
        try {//from  w  ww.j  a  va2s  .  c  om
            wait(10);
        } catch (InterruptedException ex) {
            System.out.println(
                    "Exception at CMARosaMitusEvolutionaryAlgorithm reproduce phase: " + ex.getMessage());
            System.exit(0);
        }
    }

    //La poblacin buffer es la que tiene la informacin de la calidad:
    List<Individual> sub_population = this.buffer_population.subList(0, this.getPopulation().getSize());
    //        for (int i = 0; i < sub_population.size(); i++) {
    //            population.getIndividuals().set(i, (Individual) sub_population.get(i).clone());
    //        }
    if (this.getReproductionChain() != null) {
        super.reproduce(new Population(sub_population));
    }
    synchronized (this.buffer_population) {
        for (int i = 0; i < this.getPopulation().getSize(); i++) {
            this.buffer_population.remove(0);
        }
        System.gc();
    }

}

From source file:mx.dr.ml.service.impl.AttachmentService.java

@Transactional
public void writeTempFiles() throws Exception {
    String res = "/empty.properties";
    List<Attachment> ids = dao.find("from Attachment");
    Document doc;//w  w w .j a v  a2s.  com
    for (Attachment adjunto : ids) {
        doc = dao.get(Document.class, adjunto.getIddocument());
        if (doc != null)
            FileUtils.writeToFile(Attachment.class.getResource(res).getPath().replaceFirst(res, "") + "/../../"
                    + Labels.getLabel("parametro.adjuntos.folder") + "/" + doc.getId() + "."
                    + adjunto.getFormat(), new ByteArrayInputStream(doc.getDataContent()));
    }
    System.gc();
}