Example usage for java.lang Runtime freeMemory

List of usage examples for java.lang Runtime freeMemory

Introduction

In this page you can find the example usage for java.lang Runtime freeMemory.

Prototype

public native long freeMemory();

Source Link

Document

Returns the amount of free memory in the Java Virtual Machine.

Usage

From source file:com.appdynamicspilot.action.MemoryLeakAction.java

private void populateResult() {
    Runtime runtime = Runtime.getRuntime();
    long freeMemory = runtime.freeMemory();
    long totalMemory = runtime.totalMemory();
    double freePercent = ((double) freeMemory / (double) totalMemory) * 100;
    this.request.setAttribute("freeMem", freeMemory);
    this.request.setAttribute("totalMem", totalMemory);
    this.request.setAttribute("freePercent", freePercent);
    this.request.setAttribute("inUsedPercent", (100d - freePercent));

    MemoryLeakService memoryLeakService = MemoryLeakService.instance;
    this.request.setAttribute("objectCount", memoryLeakService.getSize());
}

From source file:org.tdod.ether.taimpl.engine.jobs.StatisticsJob.java

/**
 * Runs the job./*from   w ww .j  a  v  a 2 s. c o  m*/
 * @param context the JobExecutionContext.
 */
public void execute(JobExecutionContext context) {
    Runtime runtime = Runtime.getRuntime();
    long usedMemory = runtime.totalMemory() - runtime.freeMemory();

    _log.info("Used Memory: " + usedMemory + ", Rooms: " + WorldManager.getArea().getRoomMap().size()
            + ", Mobs: " + WorldManager.getMobsInExistance().size() + ", Items: "
            + WorldManager.getItemsInExistance().size() + ", Players: " + WorldManager.getPlayers().size());
}

From source file:ShowProperties.java

public void startApp() throws MIDletStateChangeException {
    System.out.println("Vendor: " + getAppProperty("MIDlet-Vendor"));
    System.out.println("Description: " + getAppProperty("MIDlet-Description"));
    System.out.println("JadFile Version: " + getAppProperty("JadFile-Version"));
    System.out.println("MIDlet-Data-Size: " + getAppProperty("MIDlet-Data-Size"));

    Runtime rtime = Runtime.getRuntime();
    System.out.println("Total memory: " + rtime.totalMemory());
    System.out.println("Free memory: " + rtime.freeMemory());
}

From source file:com.liferay.portal.events.LogMemoryUsageAction.java

public void run(HttpServletRequest req, HttpServletResponse res) throws ActionException {

    Runtime runtime = Runtime.getRuntime();

    NumberFormat nf = NumberFormat.getInstance();

    String freeMemory = nf.format(runtime.freeMemory());
    String totalMemory = nf.format(runtime.totalMemory());
    String maxMemory = nf.format(runtime.maxMemory());

    _log.debug("Memory Usage:\t" + freeMemory + "\t" + totalMemory + "\t" + maxMemory);
}

From source file:edu.umn.cs.spatialHadoop.util.MemoryReporter.java

@Override
public void run() {
    Runtime runtime = Runtime.getRuntime();
    while (true) {
        LOG.info(String.format("Free memory %s / Total memory %s", humanReadable(runtime.freeMemory()),
                humanReadable(runtime.totalMemory())));
        try {//  w w  w .  j a v  a2s .com
            Thread.sleep(1000 * 60);
        } catch (InterruptedException e) {
        }
    }
}

From source file:fr.inria.atlanmod.neoemf.benchmarks.query.Query.java

default V callWithMemoryUsage() throws Exception {
    V result;/*w w w .  jav a  2  s  . c  o  m*/

    Runtime runtime = Runtime.getRuntime();

    runtime.gc();
    long initialUsedMemory = runtime.totalMemory() - runtime.freeMemory();
    log.info("Used memory before call: {}", FileUtils.byteCountToDisplaySize(initialUsedMemory));

    result = callWithTime();

    runtime.gc();
    long finalUsedMemory = runtime.totalMemory() - runtime.freeMemory();
    log.info("Used memory after call: {}", FileUtils.byteCountToDisplaySize(finalUsedMemory));
    log.info("Memory use increase: {}", FileUtils.byteCountToDisplaySize(finalUsedMemory - initialUsedMemory));

    return result;
}

From source file:MIDletProps.java

/**
 * Show the value of the properties/*from ww  w.j  av a2 s .  c om*/
 */
public void startApp() {
    Runtime runtime = Runtime.getRuntime();
    runtime.gc();
    long free = runtime.freeMemory();
    long total = runtime.totalMemory();

    propbuf = new StringBuffer(50);
    props = new Form("System Properties");

    props.append("Free Memory = " + free + "\n");
    props.append("Total Memory = " + total + "\n");

    props.append(showProp("microedition.configuration"));
    props.append(showProp("microedition.platform"));
    props.append(showProp("microedition.locale"));
    props.append(showProp("microedition.encoding"));
    props.append(showProp("microedition.encodingClass"));
    props.append(showProp("microedition.http_proxy"));

    props.addCommand(exitCommand);
    props.setCommandListener(this);

    display.setCurrent(props);

}

From source file:com.liferay.portal.events.GarbageCollectorAction.java

public void run(HttpSession ses) throws ActionException {

    try {//from  w  ww . j a va  2 s .co m
        Runtime runtime = Runtime.getRuntime();

        NumberFormat nf = NumberFormat.getInstance();

        _log.debug("Before GC: " + nf.format(runtime.freeMemory()) + " free, "
                + nf.format(runtime.totalMemory()) + " total, and " + nf.format(runtime.maxMemory()) + " max");

        _log.debug("Running garbage collector");

        System.gc();

        _log.debug("After GC: " + nf.format(runtime.freeMemory()) + " free, " + nf.format(runtime.totalMemory())
                + " total, and " + nf.format(runtime.maxMemory()) + " max");
    } catch (Exception e) {
        throw new ActionException(e);
    }
}

From source file:org.mule.transport.tcp.integration.BigInputStream.java

public int read() throws IOException {
    if (sent == size) {
        return -1;
    } else {//w w  w  . j  a v a 2 s .c  o m
        if (++sent > nextMessage) {
            double percent = 100l * sent / ((double) size);
            Runtime runtime = Runtime.getRuntime();
            logger.info(FORMAT.format(new Object[] { new Long(sent), new Double(percent),
                    new Long(runtime.freeMemory()), new Long(runtime.maxMemory()) }));
            nextMessage = ++printedMessages * ((int) Math.floor(((double) size) / (messages - 1)) - 1);
        }
        if (dataIndex == data.length) {
            dataIndex = 0;
        }
        return data[dataIndex++];
    }
}

From source file:org.b3log.symphony.processor.StatusProcessor.java

/**
 * Reports running status.//  ww  w  .  ja va  2s .  co m
 *
 * @param context the specified context
 * @param request the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/status", method = HTTPRequestMethod.GET)
public void reportStatus(final HTTPRequestContext context, final HttpServletRequest request,
        final HttpServletResponse response) throws Exception {
    final String key = Symphonys.get("keyOfSymphony");
    if (!key.equals(request.getParameter("key"))) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);

        return;
    }

    final JSONObject ret = new JSONObject();

    context.renderJSON(ret);

    ret.put(Common.ONLINE_VISITOR_CNT, optionQueryService.getOnlineVisitorCount());
    ret.put(Common.ARTICLE_CHANNEL_CNT, ArticleChannel.SESSIONS.size());
    ret.put(Common.ARTICLE_LIST_CHANNEL_CNT, ArticleListChannel.SESSIONS.size());

    final JSONObject memory = new JSONObject();
    ret.put("memory", memory);

    final int mb = 1024 * 1024;
    final Runtime runtime = Runtime.getRuntime();
    memory.put("totoal", runtime.totalMemory() / mb);
    memory.put("free", runtime.freeMemory() / mb);
    memory.put("used", (runtime.totalMemory() - runtime.freeMemory()) / mb);
    memory.put("max", runtime.maxMemory() / mb);

    LOGGER.info(ret.toString(SymphonyServletListener.JSON_PRINT_INDENT_FACTOR));
    ret.put(Keys.STATUS_CODE, true);
}