List of usage examples for java.lang Runtime freeMemory
public native long freeMemory();
From source file:com.viettel.logistic.wms.business.KpiLogBusiness.java
private void checkMemory(String functionName, String transactionCode) { //Getting the runtime reference from system Runtime runtime = Runtime.getRuntime(); int mb = 1024 * 1024; System.out.println("##### Heap utilization statistics [MB] #####"); System.out.println("##### Transaction code = " + transactionCode + " #####"); //Print used memory System.out.println(functionName + " Used Memory:" + (runtime.totalMemory() - runtime.freeMemory()) / mb); //Print free memory System.out.println(functionName + " Free Memory:" + runtime.freeMemory() / mb); //Print total available memory System.out.println(functionName + " Total Memory:" + runtime.totalMemory() / mb); //Print Maximum available memory System.out.println(functionName + " Max Memory:" + runtime.maxMemory() / mb); }
From source file:ffx.ui.UIDataConverter.java
/** * Rather verbose output for timed File Operations makes it easy to grep log * files for specific information./*www . j a va 2 s . co m*/ */ private void startTimer() { Runtime runtime = Runtime.getRuntime(); if (gc) { runtime.runFinalization(); runtime.gc(); } occupiedMemory = runtime.totalMemory() - runtime.freeMemory(); time -= System.nanoTime(); }
From source file:org.exem.flamingo.web.util.ApplicationInformationDisplayContextListener.java
@Override public void contextInitialized(ServletContextEvent servletContextEvent) { System.setProperty("PID", SystemUtils.getPid()); Properties properties = new Properties(); ServletContext context = servletContextEvent.getServletContext(); InputStream inputStream = null; try {/*w w w. ja v a2 s. co m*/ inputStream = context.getResourceAsStream("/WEB-INF/app.properties"); properties.load(inputStream); } catch (Exception ex) { throw new IllegalArgumentException("Cannot load a '/WEB/INF/app.properties' file.", ex); } finally { IOUtils.closeQuietly(inputStream); } // See : http://patorjk.com/software/taag/#p=display&f=Slant&t=Flamingo StringBuilder builder = new StringBuilder(); builder.append(" ________ _ \n" + " / ____/ /___ _____ ___ (_)___ ____ _____ \n" + " / /_ / / __ `/ __ `__ \\/ / __ \\/ __ `/ __ \\\n" + " / __/ / / /_/ / / / / / / / / / / /_/ / /_/ /\n" + "/_/ /_/\\__,_/_/ /_/ /_/_/_/ /_/\\__, /\\____/ \n" + " /____/ "); printHeader(builder, "Application Information"); Properties appProps = new Properties(); appProps.put("Instance", StringUtils.isEmpty(System.getProperty("instance")) ? "** UNKNOWN **" : System.getProperty("instance")); appProps.put("Version", properties.get("version")); appProps.put("Build Date", properties.get("build.timestamp")); appProps.put("Build Number", properties.get("build.number")); appProps.put("Revision Number", properties.get("revision.number")); appProps.put("Organization", properties.get("organization")); appProps.put("Homepage", properties.get("homepage")); if (context != null) { appProps.put("Application Server", context.getServerInfo() + " - Servlet API " + context.getMajorVersion() + "." + context.getMinorVersion()); } Properties systemProperties = System.getProperties(); appProps.put("Java Version", systemProperties.getProperty("java.version", UNKNOWN) + " - " + systemProperties.getProperty("java.vendor", UNKNOWN)); appProps.put("Current Working Directory", systemProperties.getProperty("user.dir", UNKNOWN)); print(builder, appProps); Properties memPros = new Properties(); final Runtime rt = Runtime.getRuntime(); final long maxMemory = rt.maxMemory() / MEGA_BYTES; final long totalMemory = rt.totalMemory() / MEGA_BYTES; final long freeMemory = rt.freeMemory() / MEGA_BYTES; final long usedMemory = totalMemory - freeMemory; memPros.put("Maximum Allowable Memory", maxMemory + "MB"); memPros.put("Total Memory", totalMemory + "MB"); memPros.put("Free Memory", freeMemory + "MB"); memPros.put("Used Memory", usedMemory + "MB"); print(builder, memPros); printHeader(builder, "Java System Properties"); Properties sysProps = new Properties(); for (final Map.Entry<Object, Object> entry : systemProperties.entrySet()) { sysProps.put(entry.getKey(), entry.getValue()); } print(builder, sysProps); printHeader(builder, "System Environments"); Map<String, String> envs = System.getenv(); Properties envProps = new Properties(); Set<String> strings = envs.keySet(); for (String key : strings) { String message = envs.get(key); envProps.put(key, message); } print(builder, envProps); WebLogbackConfigurer.initLogging(servletContextEvent.getServletContext()); System.out.println(builder.toString()); logger.info("============================================================"); logger.info(" Now starting ..... PID: " + SystemUtils.getPid()); logger.info("============================================================"); }
From source file:org.apache.maven.cli.event.ExecutionEventLogger.java
private void logStats(MavenSession session) { logger.info(chars('-', LINE_LENGTH)); long finish = System.currentTimeMillis(); long time = finish - session.getRequest().getStartTime().getTime(); String wallClock = session.getRequest().getDegreeOfConcurrency() > 1 ? " (Wall Clock)" : ""; logger.info("Total time: " + formatDuration(time) + wallClock); logger.info("Finished at: " + formatTimestamp(finish)); System.gc();//www .j a va2s .c o m Runtime r = Runtime.getRuntime(); long mb = 1024 * 1024; logger.info("Final Memory: " + (r.totalMemory() - r.freeMemory()) / mb + "M/" + r.totalMemory() / mb + "M"); }
From source file:com.h3xstream.findbugs.test.BaseDetectorTest.java
@AfterClass public void after() { System.gc();/*from w w w . j av a2 s . com*/ if (DEBUG) { Runtime rt = Runtime.getRuntime(); long inMb = 1024 * 1024; log.info("=== Memory info (Process " + ManagementFactory.getRuntimeMXBean().getName() + ") ==="); log.info("Total memory : " + rt.totalMemory() / inMb); log.info("Free memory : " + rt.freeMemory() / inMb); log.info("Memory usage : " + (rt.totalMemory() - rt.freeMemory()) / inMb); log.info("==================="); } // for(Object mock : mocksToReset) { // reset(mock); // } // mocksToReset.clear(); }
From source file:org.alfresco.repo.content.transform.TikaPoweredContentTransformer.java
private String calculateMemoryAndTimeUsage(ContentReader reader, long startTime) { long endTime = System.currentTimeMillis(); Runtime runtime = Runtime.getRuntime(); long totalMemory = runtime.totalMemory(); return String.format(USAGE_PATTERN, this.getClass().getName(), reader, (totalMemory - runtime.freeMemory()) / MEGABYTES, totalMemory / MEGABYTES, runtime.maxMemory() / MEGABYTES, (endTime - startTime)); }
From source file:ffx.ui.UIDataConverter.java
private void stopTimer(FFXSystem ffxSystem) { time += System.nanoTime();//from w w w. j a v a 2s . co m logger.log(Level.INFO, " Opened {0} with {1} atoms.\n File Op Time (msec): {2}", new Object[] { ffxSystem.toString(), ffxSystem.getAtomList().size(), time * 1.0e-9 }); Runtime runtime = Runtime.getRuntime(); if (gc) { runtime.runFinalization(); runtime.gc(); long moleculeMemory = (runtime.totalMemory() - runtime.freeMemory()) - occupiedMemory; logger.log(Level.INFO, " System Memory (Kb): {0}", moleculeMemory / KB); } occupiedMemory = runtime.totalMemory() - runtime.freeMemory(); if (gc) { logger.log(Level.INFO, " Memory In Use (Kb): {0}", occupiedMemory / KB); } }
From source file:weka.server.RootServlet.java
/** * Process a HTTP GET/*from w ww . j av a 2 s. c o m*/ * * @param request the request * @param response the response * * @throws ServletException * @throws IOException */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO if (!request.getRequestURI().equals(CONTEXT_PATH)) { return; } response.setContentType("text/html;charset=UTF-8"); response.setStatus(HttpServletResponse.SC_OK); PrintWriter out = response.getWriter(); try { out.println("<HTML>\n<HEAD>\n<TITLE>Weka server</TITLE>"); out.println("<META http-equiv=\"Refresh\" content=\"30;url=" + CONTEXT_PATH + "\">"); out.println("</HEAD>\n<BODY>"); out.println("<H2> Weka Server (" + m_server.getHostname() + ":" + m_server.getPort() + ")</H2>"); if (m_server.getMaster() != null) { out.println("Registered with master server: " + m_server.getMaster() + "<br>"); } out.println("Number of execution slots: " + m_server.getNumExecutionSlots() + "<br>"); out.println("Number of tasks executing: " + m_server.numRunningTasks() + "<br>"); out.println("Number of tasks queued: " + m_server.numQueuedTasks() + "<br>"); out.println("Load adjust factor: " + String.format("%.3f", m_server.getLoadAdjust()) + "<br>"); out.println("Server load ((#executing + #queued) * loadFactor / #execution_slots): " + m_server.getServerLoad() + "<p>"); System.gc(); Runtime run = Runtime.getRuntime(); long freeM = run.freeMemory(); long totalM = run.totalMemory(); long maxM = run.maxMemory(); out.println("Memory (free/total/max) in bytes: " + String.format("%,d", freeM) + " / " + String.format("%,d", totalM) + " / " + String.format("%,d", maxM) + "<p>"); if (m_server.getSlaves().size() > 0) { out.println("<H3>Slaves</H3>"); out.println("<p>"); out.println("<table border=\"1\">"); out.print("<tr><th>"); out.print("Host</th><th>Port</th><th>Status</th><th>Load</th></tr>\n"); Set<String> slaves = m_server.getSlaves(); for (String slave : slaves) { String[] parts = slave.split(":"); out.print("<tr>"); out.print("<td><a href=\"http://" + parts[0] + ":" + parts[1] + "\">" + parts[0] + "</a></td><td>" + parts[1] + "</td>"); double load = getSlaveLoad(m_server, slave); String okString = (load < 0) ? "connection error" : "OK"; out.print("<td>" + okString + "</td><td>" + load + "</td></tr>\n"); } out.print("</table><p>"); } out.println("<p>"); out.println("<H3>Tasks</H3>"); out.println("<table border=\"1\">"); out.print("<tr><th>"); out.print("Task name</th><th>ID</th><th>Server</th><th>Last execution</th><th>Next execution</th>" + "<th>Status</th><th>Purge</th></tr>\n"); List<WekaTaskMap.WekaTaskEntry> taskList = m_taskMap.getTaskList(); for (WekaTaskMap.WekaTaskEntry entry : taskList) { String name = entry.getName(); String id = entry.getID(); NamedTask task = m_taskMap.getTask(entry); TaskStatusInfo tsi = task.getTaskStatus(); // Date lastExecuted = m_taskMap.getExecutionTime(entry); Date lastExecuted = entry.getLastExecution(); Date nextExecution = null; if (task instanceof Scheduled) { nextExecution = ((Scheduled) task).getSchedule().nextExecution(lastExecuted); } out.print("<tr>"); out.print("<td><a href=\"" + GetTaskStatusServlet.CONTEXT_PATH + "?name=" + URLEncoder.encode(entry.toString(), "UTF-8") + "\">" + name + "</a></td>"); out.print("<td>" + id + "</td>"); String server = entry.getServer(); if (server.equals(m_server.getHostname() + ":" + m_server.getPort())) { server = "local"; } out.print("<td>"); if (!server.equals("local")) { out.print("<a href=\"http://" + server + "\">" + server + "</a></td>"); } else { out.print("" + server + "</td>"); } String formattedLastDate = " - "; String formattedNextDate = " - "; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); if (lastExecuted != null) { formattedLastDate = sdf.format(lastExecuted); } out.print("<td>" + formattedLastDate + "</td>"); if (nextExecution != null) { formattedNextDate = sdf.format(nextExecution); } out.print("<td>" + formattedNextDate + "</td>"); out.print("<td>" + GetTaskStatusServlet.taskStatusInfoToString(tsi) + "</td>"); if (tsi.getExecutionStatus() != TaskStatusInfo.PROCESSING) { out.print("<td><a href=\"" + PurgeTaskServlet.CONTEXT_PATH + "?name=" + URLEncoder.encode(entry.toString(), "UTF-8") + "\">Remove</a></td>"); } else { out.print("<td> -- </td>"); } out.print("</tr>\n"); } out.print("</table><p>"); out.println("</BODY>\n</HTML>"); } catch (Exception ex) { ex.printStackTrace(); } finally { if (out != null) { out.flush(); out.close(); out = null; } } }
From source file:org.openflamingo.engine.util.VersionConfigurer.java
/** * Notification that the web application initialization * process is starting.//from w w w . j a v a2 s . c o m * All ServletContextListeners are notified of context * initialization before any filter or servlet in the web * application is initialized. * * @param servletContextEvent {@link javax.servlet.ServletContextEvent} */ @Override public void contextInitialized(ServletContextEvent servletContextEvent) { Log4jWebConfigurer.initLogging(servletContextEvent.getServletContext()); Properties properties = new Properties(); ServletContext context = servletContextEvent.getServletContext(); InputStream inputStream = null; try { inputStream = context.getResourceAsStream("/WEB-INF/version.properties"); properties.load(inputStream); } catch (Exception ex) { throw new IllegalArgumentException("Cannot load a '/WEB/INF/version.properties' file.", ex); } finally { IOUtils.closeQuietly(inputStream); } StringBuilder builder = new StringBuilder(); printHeader(builder, "Application Information"); Properties appProps = new Properties(); appProps.put("Application", "Flamingo Workflow Engine"); appProps.put("Version", properties.get("version")); appProps.put("Build Date", properties.get("build.timestamp")); appProps.put("Build Number", properties.get("build.number")); appProps.put("Revision Number", properties.get("revision.number")); appProps.put("Build Key", properties.get("build.key")); if (context != null) { appProps.put("Application Server", context.getServerInfo() + " - Servlet API " + context.getMajorVersion() + "." + context.getMinorVersion()); } Properties systemProperties = System.getProperties(); appProps.put("Java Version", systemProperties.getProperty("java.version", UNKNOWN) + " - " + systemProperties.getProperty("java.vendor", UNKNOWN)); appProps.put("Current Working Directory", systemProperties.getProperty("user.dir", UNKNOWN)); print(builder, appProps); printHeader(builder, "JVM Heap Information"); Properties memPros = new Properties(); final Runtime rt = Runtime.getRuntime(); final long maxMemory = rt.maxMemory() / MEGA_BYTES; final long totalMemory = rt.totalMemory() / MEGA_BYTES; final long freeMemory = rt.freeMemory() / MEGA_BYTES; final long usedMemory = totalMemory - freeMemory; memPros.put("Maximum Allowable Memory", maxMemory + "MB"); memPros.put("Total Memory", totalMemory + "MB"); memPros.put("Free Memory", freeMemory + "MB"); memPros.put("Used Memory", usedMemory + "MB"); print(builder, memPros); printHeader(builder, "Java System Properties"); Properties sysProps = new Properties(); for (final Map.Entry<Object, Object> entry : systemProperties.entrySet()) { sysProps.put(entry.getKey(), entry.getValue()); } print(builder, sysProps); printHeader(builder, "System Environments"); Map<String, String> getenv = System.getenv(); Properties envProps = new Properties(); Set<String> strings = getenv.keySet(); for (String key : strings) { String message = getenv.get(key); envProps.put(key, message); } print(builder, envProps); logger.info("================================================="); logger.info(" Flamingo Workflow Engine starting..."); logger.info("=================================================\n{}", builder.toString()); }
From source file:org.wso2.carbon.mediation.statistics.monitor.EsbStatisticsConsumer.java
private void updateMemoryView(MemoryStatView view) { Runtime runtime = Runtime.getRuntime(); view.setTotalMemory(runtime.totalMemory() / MEGA); view.setFreeMemory(runtime.freeMemory() / MEGA); view.setUsedMemory((runtime.totalMemory() - runtime.freeMemory()) / MEGA); view.setMaxMemory(runtime.maxMemory() / MEGA); }