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:es.udc.gii.rosamituscma.CMARosaMitusEvolutionaryAlgorithm.java

@Override
protected synchronized void reproduce(Population population) {

    while (buffer_population.size() < this.getPopulation().getSize()) {
        try {//w ww  .  ja  v a 2s. c o m
            wait(1000);
        } 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) {
        population.setIndividuals(this.getReproductionChain().execute(this, population));
    }
    synchronized (this.buffer_population) {
        for (int i = 0; i < this.getPopulation().getSize(); i++) {
            this.buffer_population.remove(0);
        }
        System.gc();
    }

}

From source file:Classes_Home.CriarGrafico.java

public void criargrafico(JPanel jPanel3) {
        String pcs[] = { "'HP'", "'IBM'", "'LENOVO'", "'POSITIVO'", "'NACIONAL'" };
        for (int i = 0; i <= 4; i++) {
            String query = "SELECT * FROM `cpu` WHERE marca = " + pcs[i];

            try {
                st = connection.createStatement();
                rs = st.executeQuery(query);
                if (rs.last()) {
                    int aux = rs.getRow();
                    vetorParaGrafico[i] = aux;
                }//  w ww . j  a  v a  2 s . c o  m
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.setValue(vetorParaGrafico[0], "Quantidade", "HP");
        dataset.setValue(vetorParaGrafico[1], "Quantidade", "IBM");
        dataset.setValue(vetorParaGrafico[2], "Quantidade", "LENOVO");
        dataset.setValue(vetorParaGrafico[3], "Quantidade", "POSITIVO");
        dataset.setValue(vetorParaGrafico[4], "Quantidade", "NACIONAL");

        JFreeChart chart = ChartFactory.createBarChart3D(null, null, "Quantidade", dataset,
                PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        CategoryItemRenderer renderer = p.getRenderer();
        renderer.setSeriesPaint(0, new Color(80, 151, 204));
        p.setRangeGridlinePaint(Color.BLACK);
        ChartPanel panel = new ChartPanel(chart);
        panel.setDomainZoomable(true);
        panel.setVisible(true);
        jPanel3.setLayout(new BorderLayout());
        jPanel3.add(panel, BorderLayout.CENTER);
        jPanel3.revalidate();
        jPanel3.repaint();
        System.gc();
    }

From source file:com.sec.ose.osi.sdk.protexsdk.discovery.report.ReportFactory.java

public static ReportEntityList getReportEntityList(String pProjectName, ReportInfo.ReportType mReport,
        UIResponseObserver observer) {//w w  w  .j a v a 2 s  .c  o  m

    log.debug("getReportEntityList: " + pProjectName);

    String ReportType = mReport.getType();
    ReportTemplateRequest reportTemplateRequest = createReportTemplateRequest(ReportType,
            mReport.getSectionType());
    BufferedReader reportBufferedReader = generateReportFromHTML(pProjectName, reportTemplateRequest, observer);

    if (reportBufferedReader == null) {
        log.debug("Fail to generate " + pProjectName + " " + ReportType + " Report");
        observer.setFailMessage("Fail to generate " + pProjectName + " " + ReportType + " Report");
        return null;
    }

    String msgHead = " > Creating Report : " + pProjectName + "\n";
    String pMessage = " >> Generating [" + mReport.getType() + "] information from server.";
    pMessage = " >> Parsing [" + mReport.getType() + "] HTML file.";
    log.debug(pMessage);
    if (observer != null) {
        observer.pushMessageWithHeader(msgHead + pMessage);
    }

    ReportEntityList tmpReportEntityList = mReport.getCreator().createReportEntityList(reportBufferedReader);

    try {
        if (reportBufferedReader != null)
            reportBufferedReader.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    reportBufferedReader = null;
    System.gc();

    return tmpReportEntityList;
}

From source file:org.lareferencia.backend.indexer.IndexerWorker.java

@Override
public void run() {

    NetworkSnapshot snapshot = networkSnapshotRepository.findOne(this.snapshotID);
    indexer.index(snapshot);
    System.gc();
}

From source file:charva.awt.SyncThread.java

public void run() {
    for (;;) {//from w ww .j av  a  2 s.  c o  m
        AWTEvent evt = _syncQueue.getNextEvent();
        try {
            sleep(50);
        } catch (InterruptedException e) {
            LOG.warn("SyncThread: sleep interrupted!");
        }

        if (evt instanceof SyncEvent) {
            _eventQueue.postEvent(evt);

            /* If there any more SyncEvents on the queue, drain the queue;
             * there is no point in putting more than one SyncEvent on the
             * EventQueue.
             */
            while (_syncQueue.isEmpty() == false) {
                if (_syncQueue.getNextEvent() instanceof GarbageCollectionEvent) {
                    System.gc();
                    break;
                }
            }
        } else
            System.gc(); // it was a GarbageCollectionEvent
    }
}

From source file:com.almende.eve.test.TestAgents.java

/**
 * Test agents./* www  .j a v  a2 s .  c  o  m*/
 *
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws InterruptedException
 *             the interrupted exception
 */
@Test
public void testAgent() throws IOException, InterruptedException {

    final InstantiationServiceConfig isconfig = new InstantiationServiceConfig();
    final FileStateConfig state = new FileStateConfig();
    state.setPath(".wakeservices");
    state.setId("testAgents");
    isconfig.setState(state);

    final HttpTransportConfig transportConfig = new HttpTransportConfig();
    transportConfig.setServletUrl("http://localhost:8080/agents/");

    transportConfig.setServletLauncher("JettyLauncher");
    final ObjectNode jettyParms = JOM.createObjectNode();
    jettyParms.put("port", 8080);
    transportConfig.set("jetty", jettyParms);

    final AgentConfig config = new AgentConfig("example");
    config.addTransport(transportConfig);
    config.setInstantiationService(isconfig);

    ExampleAgent agent = new ExampleAgent();
    agent.setConfig(config);

    final Params callParams = new Params();
    callParams.add("message", "Hello world!");
    agent.pubSend(URI.create("http://localhost:8080/agents/example"), "helloWorld", callParams,
            new AsyncCallback<String>() {

                @Override
                public void onSuccess(final String result) {
                    LOG.warning("Received:'" + result + "'");
                }

                @Override
                public void onFailure(final Exception exception) {
                    LOG.log(Level.SEVERE, "", exception);
                    fail();
                }

            });

    LOG.warning("Sync received:'" + agent.pubSendSync(URI.create("http://localhost:8080/agents/example"),
            "helloWorld", callParams, new TypeUtil<String>() {
            }) + "'");

    // Try to get rid of the agent instance from memory
    agent = null;
    System.gc();
    System.gc();

    final AgentConfig ac = new AgentConfig("tester");
    ac.addTransport(transportConfig);
    final ExampleAgent tester = new ExampleAgent() {
    };
    tester.setConfig(ac);

    LOG.warning("Sync received:'"
            + tester.pubSendSync(URI.create("http://localhost:8080/agents/example"), "helloWorld",
                    callParams.deepCopy().put("message", "Hello world after sleep!"), new TypeUtil<String>() {
                    })
            + "'");

    tester.runComplexTypeTest(URI.create("http://localhost:8080/agents/example"));
}

From source file:com.okidokiteam.gouken.macosx.MacOSBoot.java

public synchronized void stop() throws KernelException {
    try {/*from  w  w  w .j a  v a 2 s  .  co m*/
        LOG.info("Stop hook triggered.");

        if (m_registry != null) {
            m_registry.unbind(Vault.class.getName());
            UnicastRemoteObject.unexportObject(this, true);
            UnicastRemoteObject.unexportObject(m_registry, true);
            m_registry = null;
        }
        System.gc();

        LOG.info("Shutdown complete.");

    } catch (Exception e) {
        LOG.error("Problem stopping framework.", e);
    }
}

From source file:com.openedit.util.FileUtils.java

public boolean deleteOlderVersions(String inDir) {
    System.gc();
    boolean requiresRestart = false;
    Map map = new HashMap();
    //get the parent, list the children, find the match, delete
    File dir = new File(inDir);

    File[] all = dir.listFiles();
    if (all != null) {
        for (int i = 0; i < all.length; i++) {
            File f = all[i];/*from   w  ww.j  av  a2 s.co  m*/
            String fileName = f.getName();
            int dashIndex = fileName.lastIndexOf('-');
            if (dashIndex >= 0) {
                String base = fileName.substring(0, dashIndex);
                String version = fileName.substring(dashIndex + 1);
                String highestVersion = (String) map.get(base);
                if (highestVersion == null || highestVersion.compareTo(version) < 0) {
                    map.put(base, version);
                }
            }
        }

        for (int i = 0; i < all.length; i++) {
            File f = all[i];
            String fileName = f.getName();
            int dashIndex = fileName.lastIndexOf('-');
            if (dashIndex >= 0) {
                String base = fileName.substring(0, dashIndex);
                String version = fileName.substring(dashIndex + 1);
                String highestVersion = (String) map.get(base);
                if (!version.equals(highestVersion)) {
                    if (f.delete()) {
                        log.info("deleting " + f.getName());
                    } else {
                        log.info("deleting " + f.getName() + " on exit");
                        f.deleteOnExit();
                        requiresRestart = true;
                    }
                }
            }
        }
    }
    return requiresRestart;
}

From source file:com.wwpass.connection.WWPassConnectionTest.java

@AfterClass
public static void clean() {
    System.gc();
}

From source file:com.epam.catgenome.common.AbstractControllerTest.java

@After
public void tearDown() throws IOException {
    System.gc();
    FileUtils.deleteDirectory(new File(fileManager.getBaseDirPath()));
}