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:com.almende.eve.test.TestDelete.java

/**
 * Test agents.//from   ww w . ja  v a 2 s.  c om
 * 
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws URISyntaxException
 *             the URI syntax exception
 * @throws InterruptedException
 *             the interrupted exception
 */
@Test
public void testDelete() throws IOException, URISyntaxException, InterruptedException {

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

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

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

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

    transportConfig = null;
    config = null;

    WeakReference<Agent> test = new WeakReference<Agent>(agent);
    agent.destroy();
    agent = null;

    System.gc();
    System.gc();
    try {
        Thread.sleep(1000);
    } catch (final InterruptedException e) {
    }
    System.gc();
    System.gc();

    assertNull(test.get());

    //      LOG.warning("Sleeping for profiler connection.");
    //      try {
    //         Thread.sleep(20000);
    //      } catch (final InterruptedException e) {}
}

From source file:jp.ikedam.jenkins.plugins.extensible_choice_parameter.ExtensibleChoiceParameterJenkinsRule.java

/**
 * Cleanup the temporary directory created by org.jvnet.hudson.test.TestPluginManager.
 * Needed for Jenkins < 1.510/*from   w w w  .  ja  va  2 s  .co  m*/
 */
public static synchronized void registerCleanup() {
    if (deleteThread != null) {
        return;
    }
    deleteThread = new Thread("HOTFIX: cleanup " + TestPluginManager.INSTANCE.rootDir) {
        @Override
        public void run() {
            if (TestPluginManager.INSTANCE != null && TestPluginManager.INSTANCE.rootDir != null
                    && TestPluginManager.INSTANCE.rootDir.exists()) {
                // Work as PluginManager#stop
                for (PluginWrapper p : TestPluginManager.INSTANCE.getPlugins()) {
                    p.stop();
                    p.releaseClassLoader();
                }
                TestPluginManager.INSTANCE.getPlugins().clear();
                System.gc();
                try {
                    Util.deleteRecursive(TestPluginManager.INSTANCE.rootDir);
                } catch (IOException x) {
                    x.printStackTrace();
                }
            }
        }
    };

    Runtime.getRuntime().addShutdownHook(deleteThread);
}

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

@Test
public void testLargeRequestDoesntUseTonsOfMemory() throws Exception {
    System.gc();
    long freeBefore = Runtime.getRuntime().freeMemory();
    MultiReadHttpServletRequest result = testRequestWithSize(1024 * 1024 * 20); // 20MB
    System.gc();//from ww  w .ja  va 2  s.  c  om
    long freeAfter = Runtime.getRuntime().freeMemory();
    assertTrue("memory usage should be less than 10MB: Used " + (freeBefore - freeAfter) + " bytes",
            ((freeBefore - freeAfter) < (1024 * 1024 * 10)));
    assertNotNull(result);
}

From source file:gov.nih.nci.cabig.caaers.CaaersTestCase.java

@Override
protected void setUp() throws Exception {
    super.setUp();
    applicationContext = getDeployedApplicationContext();
    setUpAuditing();// w  w  w . j  av  a  2s. com
    setUpTestAuthorization();
    System.gc();
}

From source file:gov.nih.nci.caarray.application.arraydesign.ArrayDesignMemoryTest.java

@Test
public void testLoadDesign() {
    fusionCDFData.setFileName(AffymetrixArrayDesignFiles.TEN_K_CDF.getAbsolutePath());
    fusionCDFData.read();/*  w  w  w .  j  ava  2  s . c om*/
    int numProbeSets = fusionCDFData.getHeader().getNumProbeSets();
    FusionCDFProbeSetInformation probeSetInformation = new FusionCDFProbeSetInformation();
    for (int index = 0; index < numProbeSets; index++) {
        fusionCDFData.getProbeSetInformation(index, probeSetInformation);
        handleProbeSet(probeSetInformation, fusionCDFData.getProbeSetName(index));
    }
    fusionCDFData.clear();
    fusionCDFData = null;
    probeSetInformation.clear();
    probeSetInformation = null;
    System.gc();
    System.out.println("Feature count = " + details.getFeatures().size());
    long memSize = Runtime.getRuntime().totalMemory();
    System.out.println("Mem size = " + memSize);
    System.out.println("Mem size (formatted) = " + FileUtils.byteCountToDisplaySize(memSize));
    System.out.println("Bytes per Feature = " + memSize / details.getFeatures().size());
}

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

protected static void discardAllDataForProject(String pProjectName) {
    log.debug("refresh() - " + pProjectName);

    HashSet<String> removeKeySet = new HashSet<String>();
    String removeKeyword = pProjectName + SEPERATOR;

    for (String curKey : mReportTable.keySet()) {

        if (curKey.startsWith(removeKeyword)) {
            removeKeySet.add(curKey);/*from  w  w  w . j  a v a2s.c  o  m*/
        }
    }

    for (String removeKey : removeKeySet) {
        log.debug("discardData: " + removeKey);
        mReportTable.remove(removeKey);
    }

    System.gc();
}

From source file:com.viettel.logistic.wms.business.KpiLogBusiness.java

@Override
public void createKpiLog(KpiLogDTO kpiLogDTO) {
    Session session;//from   w  w  w. j  av  a  2  s  .  c o  m
    Transaction transaction;
    try {
        session = sessionFactory.openSession();
        transaction = session.getTransaction();
        transaction.begin();
        kpiLogDAO.saveObjectSession(kpiLogDTO.toModel(), session);
        transaction.commit();
        if (session != null) {
            session.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        System.gc();
        try {
            checkMemory(kpiLogDTO.getFunctionCode(), kpiLogDTO.getTransactionCode());
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            System.out.println("finally");
        }
    }
}

From source file:com.unister.semweb.drums.api.DRUMSTest.java

@Before
public void initialise() throws Exception {
    System.gc(); // needed, that files are deletable under windows
    long[] ranges = new long[] { 0, 10, 20, 30 };
    byte[][] bRanges = KeyUtils.toByteArray(ranges);
    String[] filenames = new String[] { "1.db", "2.db", "3.db", "4.db" };
    FileUtils.deleteQuietly(new File(TestUtils.gp.DATABASE_DIRECTORY));
    hashFunction = new RangeHashFunction(bRanges, filenames, "/tmp/hash.hs");
    System.gc();//  w  ww  . j av a 2 s.co  m
}

From source file:net.bible.android.control.page.CachedKeyPage.java

/** make dictionary key lookup much faster
 * //from  w  ww . j av a 2 s  . co m
 * @return
 */
public List<Key> getCachedGlobalKeyList() {
    if (getCurrentDocument() != null && mCachedGlobalKeyList == null) {
        try {
            Log.d(TAG, "Start to create cached key list for " + getCurrentDocument());
            // this cache is cleared in setCurrentDoc
            mCachedGlobalKeyList = new ArrayList<Key>();

            for (Key key : getCurrentDocument().getGlobalKeyList()) {
                // root key has no name and can be ignored but also check for any other keys with no name
                if (!StringUtils.isEmpty(key.getName())) {
                    mCachedGlobalKeyList.add(key);
                }
            }

        } catch (OutOfMemoryError oom) {
            mCachedGlobalKeyList = null;
            System.gc();
            Log.e(TAG, "out of memory", oom);
            throw oom;
        } catch (Exception e) {
            mCachedGlobalKeyList = null;
            System.gc();
            Log.e(TAG, "Error getting keys for " + getCurrentDocument(), e);
            Dialogs.getInstance().showErrorMsg(R.string.error_occurred);
        }
        Log.d(TAG, "Finished creating cached key list len:" + mCachedGlobalKeyList.size());
    }
    return mCachedGlobalKeyList;
}

From source file:io.fabric8.insight.metrics.MetricsTest.java

@Test
public void testDefault() throws Exception {
    Query query = new Query("test",
            new HashSet<Request>(Arrays.asList(
                    new MBeanAttrs("memory", "java.lang:type=Memory",
                            Arrays.asList("HeapMemoryUsage", "NonHeapMemoryUsage")),
                    new MBeanOpers("deadlocks", "java.lang:type=Threading", "dumpAllThreads",
                            Arrays.<Object>asList(true, true),
                            Arrays.<String>asList(boolean.class.getName(), boolean.class.getName())))),
            null, null, null, 0, 0);/*w ww. java  2s. co  m*/

    System.gc();

    QueryResult qrs = JmxUtils.execute(new Server("local"), query, ManagementFactory.getPlatformMBeanServer());
    String output = new Renderer().render(qrs);

    Map map = new ObjectMapper().readValue(output, Map.class);
    assertEquals("local", map.get("host"));
    assertNotNull(map.get("@timestamp"));
}