Example usage for java.lang Runtime totalMemory

List of usage examples for java.lang Runtime totalMemory

Introduction

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

Prototype

public native long totalMemory();

Source Link

Document

Returns the total amount of memory in the Java virtual machine.

Usage

From source file:com.aurel.track.admin.server.status.ServerStatusBL.java

private static void loadJavaRuntimeInfo(ServerStatusTO serverStatusTO) {
    Runtime rt = Runtime.getRuntime();
    long mbyte = 1024 * 1024;
    serverStatusTO.setJavaVersion(System.getProperty("java.version"));
    serverStatusTO.setJavaVendor(System.getProperty("java.vendor"));
    serverStatusTO.setJavaHome(System.getProperty("java.home"));
    serverStatusTO.setJavaVMVersion(System.getProperty("java.vm.version"));
    serverStatusTO.setJavaVMVendor(System.getProperty("java.vm.vendor"));
    serverStatusTO.setJavaVMName(System.getProperty("java.vm.name"));

    serverStatusTO.setJavaVMfreeMemory(rt.freeMemory() / mbyte);
    serverStatusTO.setJavaVMmaxMemory(rt.maxMemory() / mbyte);
    serverStatusTO.setJavaVMtotalMemory(rt.totalMemory() / mbyte);
    serverStatusTO/*from   w w w  .  j a v a  2 s  .  c om*/
            .setJavaVMusedMemory(serverStatusTO.getJavaVMtotalMemory() - serverStatusTO.getJavaVMfreeMemory());
}

From source file:edu.stanford.epadd.launcher.Splash.java

public static String getMemoryStats() {
    Runtime r = Runtime.getRuntime();
    System.gc();//from www .  j ava 2s .  co m
    return r.freeMemory() / MB + " MB free, " + (r.totalMemory() / MB - r.freeMemory() / MB) + " MB used, "
            + r.maxMemory() / MB + " MB max, " + r.totalMemory() / MB + " MB total";
}

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.github.fedorchuck.webstore.web.controllers.SystemInfoController.java

@RequestMapping(value = "", method = GET)
public ModelAndView index() {
    ModelAndView model = new ModelAndView("sysinfo");

    final double mb = 1024 * 1024;
    Runtime runtime = Runtime.getRuntime();
    long usedRam = runtime.totalMemory() - runtime.freeMemory();

    Map<String, Double> mem = new TreeMap<>();
    mem.put("Used memory", usedRam / mb);
    mem.put("Total memory", runtime.totalMemory() / mb);
    mem.put("Free memory", runtime.freeMemory() / mb);

    model.getModel().put("mem", mem);

    //model.addObject("userActions", new UserActions());

    return model;
}

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

/**
 * Runs the job.//from  w w w  . jav 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:fr.inria.atlanmod.neoemf.benchmarks.query.Query.java

default V callWithMemoryUsage() throws Exception {
    V result;/*from  ww  w .  ja  v 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:org.b3log.symphony.processor.StatusProcessor.java

/**
 * Reports running status./*from   w w  w.  java2s  . c  om*/
 *
 * @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);
}

From source file:io.cloudslang.worker.management.monitor.WorkerMonitorsImpl.java

@Override
public synchronized Map<WorkerMonitorInfoEnum, Serializable> getMonitorInfo() {
    try {/*ww  w  .j  a  va2  s .c o  m*/
        Map<WorkerMonitorInfoEnum, Serializable> monitorInfo = Maps.newHashMap();

        Runtime runtime = Runtime.getRuntime();
        monitorInfo.put(WorkerMonitorInfoEnum.TOTAL_MEMORY, runtime.totalMemory());
        monitorInfo.put(WorkerMonitorInfoEnum.FREE_MEMORY, runtime.freeMemory());
        monitorInfo.put(WorkerMonitorInfoEnum.MAX_MEMORY, runtime.maxMemory());

        monitorInfo.put(WorkerMonitorInfoEnum.WORKER_ID, workerManager.getWorkerUuid());

        monitorInfo.put(WorkerMonitorInfoEnum.EXECUTION_THREADS_AMOUNT,
                workerManager.getExecutionThreadsCount());

        monitorInfo.put(WorkerMonitorInfoEnum.OUTBUFFER_CAPACITY, outBuffer.getCapacity());

        monitorInfo.put(WorkerMonitorInfoEnum.INBUFFER_CAPACITY, inBuffer.getCapacity());

        for (WorkerMonitor monitor : monitors) {
            monitor.captureMonitorInfo(monitorInfo);
        }

        monitorInfo.put(WorkerMonitorInfoEnum.MONITOR_START_TIME, monitorStartTime);
        monitorInfo.put(WorkerMonitorInfoEnum.MONITOR_END_TIME, System.currentTimeMillis());

        return monitorInfo;
    } finally {
        resetMonitor();
    }
}

From source file:org.openmrs.module.emrmonitor.metric.JavaRuntimeMetricProducer.java

/**
 * @return a list of produced metrics//from w  ww .  j a  va 2 s .  co  m
 */
@Override
public Map<String, String> produceMetrics() {

    Map<String, String> metrics = new LinkedHashMap<String, String>();

    // Memory
    Runtime runtime = Runtime.getRuntime();
    metrics.put("memory.total", FormatUtil.formatBytes(runtime.totalMemory()));
    metrics.put("memory.total.bytes", Long.toString(runtime.totalMemory()));
    metrics.put("memory.free", FormatUtil.formatBytes(runtime.freeMemory()));
    metrics.put("memory.free.bytes", Long.toString(runtime.freeMemory()));
    metrics.put("memory.maximum", FormatUtil.formatBytes(runtime.maxMemory()));
    metrics.put("memory.maximum.bytes", Long.toString(runtime.maxMemory()));

    // Date/time
    Calendar cal = Calendar.getInstance();
    metrics.put("datetime.display", DateFormat.getDateTimeInstance().format(cal.getTime()));
    metrics.put("datetime.date", DateFormatUtils.ISO_DATE_FORMAT.format(cal));
    metrics.put("datetime.time", DateFormatUtils.ISO_TIME_NO_T_FORMAT.format(cal));
    metrics.put("datetime.timezone", cal.getTimeZone().getDisplayName());

    // Java
    Properties sp = System.getProperties();
    metrics.put("version", sp.getProperty("java.version"));
    metrics.put("vendor", sp.getProperty("java.vendor"));
    metrics.put("jvmVersion", sp.getProperty("java.vm.version"));
    metrics.put("jvmVendor", sp.getProperty("java.vm.vendor"));
    metrics.put("runtimeName", sp.getProperty("java.runtime.name"));
    metrics.put("runtimeVersion", sp.getProperty("java.runtime.version"));
    metrics.put("user.name", sp.getProperty("user.name"));
    metrics.put("user.language", sp.getProperty("user.language"));
    metrics.put("user.timezone", sp.getProperty("user.timezone"));
    metrics.put("user.directory", sp.getProperty("user.dir"));
    metrics.put("encoding", sp.getProperty("sun.jnu.encoding"));
    metrics.put("tempDirectory", sp.getProperty("java.io.tmpdir"));

    return metrics;
}

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());
}