Example usage for java.lang Runtime maxMemory

List of usage examples for java.lang Runtime maxMemory

Introduction

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

Prototype

public native long maxMemory();

Source Link

Document

Returns the maximum amount of memory that the Java virtual machine will attempt to use.

Usage

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

public static String getMemoryStats() {
    Runtime r = Runtime.getRuntime();
    System.gc();//from w  w  w  .ja va  2s. c  o  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:it.damore.tomee.envmonitor.services.EnvMonitorService.java

@GET
@Path("monitor")
@Produces({ MediaType.APPLICATION_JSON })
public EnvironmentConfig getEnvConfig() throws IllegalAccessException, InvocationTargetException {
    logger.info("received a request...");

    int mb = 1024 * 1024;
    //Getting the runtime reference from system
    Runtime runtime = Runtime.getRuntime();

    EnvironmentConfig b = new EnvironmentConfig();
    b.setMaxMemory(runtime.maxMemory() / mb);
    b.setFreeMemory(runtime.freeMemory() / mb);
    b.setTotalMemory(runtime.totalMemory() / mb);
    b.setSystemProperties(System.getProperties());

    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    LocalRuntimeMXBean myRuntimeMXBean = new LocalRuntimeMXBean();
    BeanUtils.copyProperties(myRuntimeMXBean, runtimeMXBean);
    b.setRuntimeMXBean(myRuntimeMXBean);

    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    LocalMemoryMXBean myMemoryMXBean = new LocalMemoryMXBean();
    myMemoryMXBean.setHeapMemoryUsage(memoryMXBean.getHeapMemoryUsage());
    myMemoryMXBean.setNonHeapMemoryUsage(memoryMXBean.getNonHeapMemoryUsage());
    myMemoryMXBean.setObjectPendingFinalizationCount(memoryMXBean.getObjectPendingFinalizationCount());
    b.setMemoryMXBean(myMemoryMXBean);//  w  w w  .ja v a  2 s  .  c  o  m

    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    LocalOperatingSystemMXBean myOperatingSystemMXBean = new LocalOperatingSystemMXBean();
    BeanUtils.copyProperties(myOperatingSystemMXBean, operatingSystemMXBean);
    b.setOperatingSystemMXBean(myOperatingSystemMXBean);

    return b;
}

From source file:org.gedantic.web.servlet.FileUploadHandler.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    LOG.debug(">doPost");

    // process only if its multipart content
    if (ServletFileUpload.isMultipartContent(request)) {
        try {//from   w w  w  .ja v  a  2s.c om
            List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
            long length = 0;
            for (FileItem item : multiparts) {
                if (!item.isFormField()) {
                    if (!item.getName().toLowerCase().endsWith(".ged")
                            && !item.getName().toLowerCase().endsWith(".gedcom")) {
                        LOG.info("Upload file " + item.getName() + " doesn't end in .ged or .gedcom");
                        throw new RuntimeException(
                                "Upload file " + item.getName() + " doesn't end in .ged or .gedcom");
                    }
                    if (item.getSize() > MAX_MB * 1024 * 1024) {
                        LOG.info("Upload file " + item.getName() + " exceeds " + MAX_MB + "MB limit - was "
                                + item.getSize());
                        throw new RuntimeException("Upload file " + item.getName() + " exceeds " + MAX_MB
                                + "MB limit - was " + item.getSize());
                    }
                    String name = new File(item.getName()).getName();
                    String fullPathAndName = UPLOAD_DIRECTORY + File.separator + name;
                    File file = new File(fullPathAndName);
                    item.write(file);
                    length = file.length();
                    LOG.info("Wrote " + fullPathAndName + " (" + length + " bytes)");

                    new ParserAndLoader(request, response, file).parseAndLoadIntoSession();
                }
            }
        } catch (RuntimeException ex) {
            LOG.error("Unable to upload file: " + ex.getMessage());
            response.setStatus(403);
        } catch (Exception ex) {
            LOG.error("Unable to upload file: ", ex);
            response.setStatus(403);
        }
    }

    Runtime rt = Runtime.getRuntime();
    long maxMemory = rt.maxMemory();
    long freeMemory = rt.freeMemory();
    LOG.info("fileUploaded - freeMemory:" + Double.toString(freeMemory / (1024 * 1024)) + " maxMemory:"
            + Double.toString(maxMemory / (1024 * 1024)));

    LOG.debug("<doPost");
}

From source file:onlinefrontlines.admin.web.ServerInfoAction.java

/**
  * Execute the action/*  w w w  . j a va  2  s .  c  o  m*/
  */
protected WebView execute() throws Exception {
    Runtime r = Runtime.getRuntime();

    // Get stats
    date = new Date().toString();
    committedMemory = r.totalMemory();
    maxMemory = r.maxMemory();
    usedMemory = committedMemory - r.freeMemory();
    cpuCount = Runtime.getRuntime().availableProcessors();
    os = System.getProperty("os.name") + " (" + System.getProperty("sun.os.patch.level") + ") "
            + System.getProperty("os.arch") + " " + System.getProperty("os.version");
    jvm = System.getProperty("java.runtime.name") + " " + System.getProperty("java.runtime.version") + " "
            + System.getProperty("java.vm.name");
    for (String s : DbConnectionPool.getInstance().getDataSources().keySet())
        dataSourceStatus.put(s, getDataSourceStatus(s));
    servletContainer = servletContext.getServerInfo();

    return getSuccessView();
}

From source file:eu.openanalytics.rsb.component.SystemHealthResource.java

@GET
@Path("/info")
@Produces({ Constants.RSB_XML_CONTENT_TYPE, Constants.RSB_JSON_CONTENT_TYPE })
public NodeInformation getInfo(@Context final ServletContext sc) {
    final NodeInformation info = Util.REST_OBJECT_FACTORY.createNodeInformation();

    info.setName(getConfiguration().getNodeName());
    info.setHealthy(nodeHealthy.get());//from w  ww.j a v  a2s .  c  o m
    info.setRsbVersion(getClass().getPackage().getImplementationVersion());
    info.setServletContainerInfo(sc.getServerInfo());

    final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    info.setOsLoadAverage(operatingSystemMXBean.getSystemLoadAverage());

    final Runtime runtime = Runtime.getRuntime();
    info.setJvmMaxMemory(runtime.maxMemory());
    info.setJvmFreeMemory(runtime.freeMemory());

    final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    final long uptimeMilliseconds = runtimeMXBean.getUptime();
    info.setUptime(uptimeMilliseconds);
    info.setUptimeText(DurationFormatUtils.formatDurationWords(uptimeMilliseconds, true, true));

    return info;
}

From source file:org.gedantic.web.servlet.AnalyzerServlet.java

/**
 * Servlet for handling all analysis requests
 * /* ww  w .  j  a v a2 s. co m*/
 * @param req
 *            the http request
 * @param resp
 *            the http response
 * @throws ServletException
 *             if there is a code-related problemDescription
 * @throws IOException
 *             if there is a network or storage-related problemDescription
 */
private void process(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    HttpSession session = req.getSession();
    Gedcom g = (Gedcom) session.getAttribute(Constants.GEDCOM);
    IAnalyzer a = null;

    String analyzerId = req.getParameter("analyzerId");
    if (analyzerId != null) {
        a = AnalyzerList.getInstance().getAnalyzers().get(analyzerId);
        req.setAttribute(Constants.ANALYSIS_ID, a.getId());
        req.setAttribute(Constants.ANALYSIS_NAME, a.getName());
        req.setAttribute(Constants.ANALYSIS_DESCRIPTION, a.getDescription());
    }

    if (g == null) {
        LOG.info("Redirecting from " + req.getRequestURI()
                + " to upload page because there is no gedcom in session");
        req.setAttribute(Constants.ALERT_MESSAGE, "Please upload a GEDCOM to analyze");
        req.setAttribute(Constants.ALERT_MESSAGE_TYPE, "alert alert-warning");
        req.getRequestDispatcher(Constants.URL_UPLOAD_PAGE).forward(req, resp);
        return;
    }

    if (a == null) {
        LOG.info("Redirecting from " + req.getRequestURI()
                + " to upload page because the analysis ID could not be interpreted");
        req.setAttribute(Constants.ALERT_MESSAGE, "Unknown analysis type");
        req.setAttribute(Constants.ALERT_MESSAGE_TYPE, "alert alert-danger");
        req.getRequestDispatcher(Constants.URL_UPLOAD_PAGE).forward(req, resp);
        return;

    }

    Runtime rt = Runtime.getRuntime();
    long maxMemory = rt.maxMemory();
    long freeMemory = rt.freeMemory();
    LOG.info("before analysis " + a.getId() + " - freeMemory:" + Double.toString(freeMemory / (1024 * 1024))
            + " maxMemory:" + Double.toString(maxMemory / (1024 * 1024)));

    List<AnalysisResult> results = a.analyze(g);
    Collections.sort(results, new AnalysisResultComparator());

    maxMemory = rt.maxMemory();
    freeMemory = rt.freeMemory();
    LOG.info("after analysis " + a.getId() + " - freeMemory:" + Double.toString(freeMemory / (1024 * 1024))
            + " maxMemory:" + Double.toString(maxMemory / (1024 * 1024)));

    if ("true".equals(req.getParameter("excel"))) {
        @SuppressWarnings("resource")
        Workbook wb = new WorkbookCreator(a, results).create();

        resp.setContentType("application/vnd.ms-excel");
        resp.setHeader("Content-disposition",
                "attachment; filename=" + StringEscapeUtils.escapeHtml(a.getName() + ".xlsx"));

        wb.write(resp.getOutputStream());
        resp.getOutputStream().flush();

    } else {
        req.setAttribute(Constants.RESULTS, results);
        req.getRequestDispatcher("results.tiles").forward(req, resp);
    }
}

From source file:hydrograph.ui.joblogger.JobLogger.java

/**
 * //from   w ww  .j  a  va 2  s  .  co  m
 * Logs runtime properties
 * 
 * @param jobLogger
 */
private void logRuntimeInformation(AbstractJobLogger jobLogger) {
    Runtime runtime = Runtime.getRuntime();
    long maxMemory = runtime.maxMemory();
    jobLogger.logWithNoTimeStamp("Max Memory: " + Long.toString(maxMemory / 1024));
    long allocatedMemory = runtime.totalMemory();
    jobLogger.logWithNoTimeStamp("Allocated Memory:  " + Long.toString(allocatedMemory / 1024));
    long freeMemory = runtime.freeMemory();
    jobLogger.logWithNoTimeStamp("Free Memory: " + Long.toString(freeMemory / 1024));
    jobLogger.logWithNoTimeStamp(
            "Total free memory: " + Long.toString((freeMemory + (maxMemory - allocatedMemory)) / 1024));
    long used = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
    jobLogger.logWithNoTimeStamp("Used Memory : " + Long.toString(used));
}

From source file:alluxio.util.JvmPauseMonitor.java

private String getMemoryInfo() {
    Runtime runtime = Runtime.getRuntime();
    return "max memory = " + runtime.maxMemory() / (1024 * 1024) + "M total memory = "
            + runtime.totalMemory() / (1024 * 1024) + "M free memory = " + runtime.freeMemory() / (1024 * 1024)
            + "M";
}

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

public int read() throws IOException {
    if (sent == size) {
        return -1;
    } else {/*from  w  w  w. j  a  va  2s  .  com*/
        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.loklak.api.susi.StatusService.java

@Override
public JSONObject serviceImpl(Query post, HttpServletResponse response, Authorization rights,
        JSONObjectWithDefault permissions) throws APIException {

    post.setResponse(response, "application/javascript");

    // generate json
    Runtime runtime = Runtime.getRuntime();
    JSONObject json = new JSONObject(true);
    JSONObject system = new JSONObject(true);
    system.put("assigned_memory", runtime.maxMemory());
    system.put("used_memory", runtime.totalMemory() - runtime.freeMemory());
    system.put("available_memory", runtime.maxMemory() - runtime.totalMemory() + runtime.freeMemory());
    system.put("cores", runtime.availableProcessors());
    system.put("threads", Thread.activeCount());
    system.put("runtime", System.currentTimeMillis() - Caretaker.startupTime);
    system.put("load_system_average", OS.getSystemLoadAverage());
    system.put("load_system_cpu", OS.getSystemCpuLoad());
    system.put("load_process_cpu", OS.getProcessCpuLoad());
    system.put("server_threads", SusiServer.getServerThreads());
    system.put("server_uri", SusiServer.getServerURI());

    JSONObject index = new JSONObject(true);
    JSONObject messages = new JSONObject(true);
    JSONObject queue = new JSONObject(true);
    messages.put("queue", queue);
    JSONObject users = new JSONObject(true);
    JSONObject queries = new JSONObject(true);
    JSONObject accounts = new JSONObject(true);
    JSONObject user = new JSONObject(true);
    index.put("messages", messages);
    index.put("users", users);
    index.put("queries", queries);
    index.put("accounts", accounts);
    index.put("user", user);

    JSONObject client_info = new JSONObject(true);
    client_info.put("RemoteHost", post.getClientHost());
    client_info.put("IsLocalhost", post.isLocalhostAccess() ? "true" : "false");

    JSONObject request_header = new JSONObject(true);
    Enumeration<String> he = post.getRequest().getHeaderNames();
    while (he.hasMoreElements()) {
        String h = he.nextElement();
        request_header.put(h, post.getRequest().getHeader(h));
    }/*from  w  ww . ja  v a  2 s  . c  o m*/
    client_info.put("request_header", request_header);

    json.put("system", system);
    json.put("index", index);
    json.put("client_info", client_info);

    return json;
}