List of usage examples for java.lang Runtime maxMemory
public native long maxMemory();
From source file:eu.stratosphere.nephele.instance.HardwareDescriptionFactory.java
/** * Returns the size of free memory in bytes available to the JVM. * // w w w . jav a2s.c om * @return the size of the free memory in bytes available to the JVM or <code>-1</code> if the size cannot be * determined */ private static long getSizeOfFreeMemory() { float fractionToUse = GlobalConfiguration.getFloat(ConfigConstants.TASK_MANAGER_MEMORY_FRACTION_KEY, ConfigConstants.DEFAULT_MEMORY_MANAGER_MEMORY_FRACTION); Runtime r = Runtime.getRuntime(); long max = r.maxMemory(); long total = r.totalMemory(); long free = r.freeMemory(); long available = max - total + free; return (long) (fractionToUse * available); }
From source file:org.eclipse.wb.internal.core.editor.errors.report2.EnvironmentFileReportInfo.java
private static String createContents(IProject project) { String c = ""; c += "Product Name: " + BrandingUtils.getBranding().getProductName() + CR; c += "Product Version: " + ProductInfo.getProduct().getVersion() + "[" + ProductInfo.getProduct().getBuild() + "]" + CR; c += "Installation Path: " + getInstallationPath() + CR; c += "Eclipse Version: " + PlatformInfo.getEclipseVersion().toString() + CR; c += "Eclipse Build Name: " + PlatformInfo.getEclipseBuildName() + CR; c += "Eclipse Build ID: " + PlatformInfo.getEclipseBuildId() + CR; c += "IDE Name: " + PlatformInfo.getIDEName() + CR; c += "IDE Version: " + PlatformInfo.getIDEVersionString() + CR; c += "IDE NL: " + PlatformInfo.getIDENL() + CR; c += "Eclipse Commands: " + StringUtils.replaceChars(getSystemProperty("eclipse.commands"), "\n\r", " ") + CR;//w ww.j a va 2 s. c o m c += "Eclipse VM: " + getSystemProperty("eclipse.vm") + CR; c += "Eclipse VM Args: " + getSystemProperty("eclipse.vmargs") + CR; c += "OS Name: " + getSystemProperty("os.name") + CR; c += "OS Arch: " + getSystemProperty("os.arch") + CR; c += "OS Version: " + getSystemProperty("os.version") + CR; String linuxDescription = getLinuxDescription(); if (!StringUtils.isEmpty(linuxDescription)) { c += "Linux Description: " + linuxDescription + CR; } String m_mozillaResult = tryCreateMozilla(); if (!StringUtils.isEmpty(m_mozillaResult)) { c += "Browser Creation Result: " + m_mozillaResult + CR; } Runtime runtime = Runtime.getRuntime(); c += "Available Processors: " + runtime.availableProcessors() + CR; c += "Memory Max: " + runtime.maxMemory() + CR; c += "Memory Total: " + runtime.totalMemory() + CR; c += "Memory Free: " + runtime.freeMemory() + CR; c += "Java Vendor: " + getSystemProperty("java.vendor") + CR; c += "Java Version: " + getSystemProperty("java.version") + CR; c += "Java Library Path: " + CR + getSystemProperty("java.library.path") + CR; c += "Project Class Path: " + CR + getClassPath(project) + CR; return c; }
From source file:com.eryansky.utils.SigarUtil.java
/** * ??/* w w w . j ava2 s . c om*/ * @throws Exception */ public static ServerStatus getServerStatus() throws Exception { ServerStatus status = new ServerStatus(); status.setServerTime(DateFormatUtils.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss")); status.setServerName(System.getenv().get("COMPUTERNAME")); Runtime rt = Runtime.getRuntime(); //status.setIp(InetAddress.getLocalHost().getHostAddress()); status.setJvmTotalMem(rt.totalMemory() / (1024 * 1024)); status.setJvmFreeMem(rt.freeMemory() / (1024 * 1024)); status.setJvmMaxMem(rt.maxMemory() / (1024 * 1024)); Properties props = System.getProperties(); status.setServerOs(props.getProperty("os.name") + " " + props.getProperty("os.arch") + " " + props.getProperty("os.version")); status.setJavaHome(props.getProperty("java.home")); status.setJavaVersion(props.getProperty("java.version")); status.setJavaTmpPath(props.getProperty("java.io.tmpdir")); Sigar sigar = new Sigar(); getServerCpuInfo(sigar, status); getServerDiskInfo(sigar, status); getServerMemoryInfo(sigar, status); return status; }
From source file:org.apache.hadoop.hdfs.server.namenode.Namenode2Agent.java
private static void startup() throws Exception { System.setProperty("PID", SystemUtils.getPid()); try {/*www. ja v a2 s .co m*/ Log4jConfigurer.initLogging(System.getProperty("location"), Long.parseLong(System.getProperty("refreshInterval"))); } catch (Exception ex) { System.out.println("Flamingo 2 :: Cannot load Log4J configuration file. Use Resource Manager Log4J."); } StringBuilder builder = new StringBuilder(); LOG.info("============================================================\n" + "Now starting Flamingo 2 - Namenode 2 Agent (" + SystemUtils.getPid() + ") ....\n" + "============================================================"); builder.append( " ________ _ __ __ __ ___ __ \n" + " / ____/ /___ _____ ___ (_)___ ____ _____ / / / /___ _____/ /___ ____ ____ / | ____ ____ ____ / /_\n" + " / /_ / / __ `/ __ `__ \\/ / __ \\/ __ `/ __ \\ / /_/ / __ `/ __ / __ \\/ __ \\/ __ \\ / /| |/ __ `/ _ \\/ __ \\/ __/\n" + " / __/ / / /_/ / / / / / / / / / / /_/ / /_/ / / __ / /_/ / /_/ / /_/ / /_/ / /_/ / / ___ / /_/ / __/ / / / /_ \n" + "/_/ /_/\\__,_/_/ /_/ /_/_/_/ /_/\\__, /\\____/ /_/ /_/\\__,_/\\__,_/\\____/\\____/ .___/ /_/ |_\\__, /\\___/_/ /_/\\__/ \n" + " /____/ /_/ /____/ "); SortedProperties properties = new SortedProperties(); InputStream is = ResourceUtils.getResource("classpath:/version.properties").getInputStream(); properties.load(is); is.close(); printHeader(builder, "Application Information"); SortedProperties appProps = new SortedProperties(); appProps.put("Application", "Flamingo Hadoop Namenode 2 Monitoring Agent"); 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")); SortedProperties systemProperties = new SortedProperties(); systemProperties.putAll(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, "Hadoop Information"); SortedProperties hadoopProps = new SortedProperties(); hadoopProps.put("Version", VersionInfo.getVersion()); // FIXME hadoopProps.put("Build Version", VersionInfo.getBuildVersion()); print(builder, hadoopProps); 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("Total Memory", totalMemory + "MB"); memPros.put("Maximum Allowable Memory", maxMemory + "MB"); memPros.put("Used Memory", usedMemory + "MB"); memPros.put("Free Memory", freeMemory + "MB"); print(builder, memPros); printHeader(builder, "Java System Properties"); SortedProperties sysProps = new SortedProperties(); 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(); SortedProperties envProps = new SortedProperties(); Set<String> strings = getenv.keySet(); for (String key : strings) { String message = getenv.get(key); envProps.put(key, message); } print(builder, envProps); /* LogbackConfigurer.initLogging("classpath:/logback.xml"); */ System.out.println(builder.toString()); System.out.println( "================================================================================================"); System.out.println(" Flamingo Hadoop Namenode 2 Monitoring Agent starting... (" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + ")"); System.out.println( "================================================================================================"); }
From source file:Util.java
/** * Returns a report of used and available memory. * /*from w w w .jav a2s . c om*/ * @return a report of used and available memory */ @SuppressWarnings("boxing") public static String memoryReport() { Runtime runtime = Runtime.getRuntime(); long freemem = runtime.freeMemory(); long totalmem = runtime.totalMemory(); return String.format( "%.1f MB of memory free out of %.1f MB total in JVM (%.1f MB used). Configured maximum: %.1f MB.", freemem / BYTES_PER_MB, totalmem / BYTES_PER_MB, (totalmem - freemem) / BYTES_PER_MB, runtime.maxMemory() / BYTES_PER_MB); }
From source file:org.tranche.logs.LogUtil.java
/** * /* w w w . ja v a 2s . c o m*/ * @return */ public static final String getEnvironmentDump() { StringBuffer buf = new StringBuffer(); buf.append("Build: @buildNumber" + "\n"); try { buf.append("Internet host/address: " + java.net.InetAddress.getLocalHost() + "\n"); } catch (Exception e) { } Runtime rt = Runtime.getRuntime(); long fm = rt.freeMemory(); long tm = rt.totalMemory(); long mm = rt.maxMemory(); buf.append("Memory: "); buf.append("\n"); buf.append(" Free: " + TextUtil.formatBytes(fm)); buf.append("\n"); buf.append(" Used: " + TextUtil.formatBytes(tm - fm)); buf.append("\n"); buf.append(" Total: " + TextUtil.formatBytes(tm)); buf.append("\n"); buf.append(" Maximum:" + TextUtil.formatBytes(mm)); buf.append("\n" + "\n" + "\n"); return buf.toString(); }
From source file:com.jaspersoft.studio.community.utils.CommunityAPIUtils.java
/** * @return software and hardware info.//www . ja va 2s . c om */ public static String getHardwareSoftwareInfo() { BrandingInfo currBranding = JaspersoftStudioPlugin.getInstance().getBrandingInformation(); String c = ""; //$NON-NLS-1$ c += "Product Name: " + currBranding.getProductName() + CR; //$NON-NLS-1$ c += "Product Version: " + currBranding.getProductVersion() + CR; //$NON-NLS-1$ c += "Installation Path: " + getInstallationPath(currBranding.getProductMainBundleID()) + CR; //$NON-NLS-1$ c += "Eclipse Version: " + PlatformInfo.getEclipseVersion().toString() //$NON-NLS-1$ + CR; c += "Eclipse Build Name: " + PlatformInfo.getEclipseBuildName() + CR; //$NON-NLS-1$ c += "Eclipse Build ID: " + PlatformInfo.getEclipseBuildId() + CR; //$NON-NLS-1$ c += "IDE Name: " + PlatformInfo.getIDEName() + CR; //$NON-NLS-1$ c += "IDE Version: " + PlatformInfo.getIDEVersionString() + CR; //$NON-NLS-1$ c += "IDE NL: " + PlatformInfo.getIDENL() + CR; //$NON-NLS-1$ c += "Eclipse Commands: " //$NON-NLS-1$ + StringUtils.replaceChars(getSystemProperty("eclipse.commands"), "\n\r", " ") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + CR; c += "Eclipse VM: " + getSystemProperty("eclipse.vm") + CR; //$NON-NLS-1$ //$NON-NLS-2$ c += "Eclipse VM Args: " + getSystemProperty("eclipse.vmargs") + CR; //$NON-NLS-1$ //$NON-NLS-2$ c += "OS Name: " + getSystemProperty("os.name") + CR; //$NON-NLS-1$ //$NON-NLS-2$ c += "OS Arch: " + getSystemProperty("os.arch") + CR; //$NON-NLS-1$ //$NON-NLS-2$ c += "OS Version: " + getSystemProperty("os.version") + CR; //$NON-NLS-1$ //$NON-NLS-2$ String linuxDescription = getLinuxDescription(); if (!StringUtils.isEmpty(linuxDescription)) { c += "Linux Description: " + linuxDescription + CR; //$NON-NLS-1$ } String m_mozillaResult = tryCreateMozilla(); if (!StringUtils.isEmpty(m_mozillaResult)) { c += "Browser Creation Result: " + m_mozillaResult + CR; //$NON-NLS-1$ } Runtime runtime = Runtime.getRuntime(); c += "Available Processors: " + runtime.availableProcessors() + CR; //$NON-NLS-1$ c += "Memory Max: " + runtime.maxMemory() + CR; //$NON-NLS-1$ c += "Memory Total: " + runtime.totalMemory() + CR; //$NON-NLS-1$ c += "Memory Free: " + runtime.freeMemory() + CR; //$NON-NLS-1$ c += "Java Vendor: " + getSystemProperty("java.vendor") + CR; //$NON-NLS-1$ //$NON-NLS-2$ c += "Java Version: " + getSystemProperty("java.version") + CR; //$NON-NLS-1$ //$NON-NLS-2$ c += "Java Library Path: " + getSystemProperty("java.library.path") + CR; //$NON-NLS-1$ //$NON-NLS-2$ return c; }
From source file:org.apache.axiom.attachments.impl.PartFactory.java
/** * This method checks the configured threshold and * the current runtime information. If it appears that we could * run out of memory, the threshold is reduced. * /*w ww . j a v a2s. co m*/ * This method allows the user to request a much larger threshold without * fear of running out of memory. Using a larger in memory threshold generally * results in better throughput. * * @param configThreshold * @param inflight * @return threshold */ private static int getRuntimeThreshold(int configThreshold, int inflight) { // Determine how much free memory is available Runtime r = Runtime.getRuntime(); long totalmem = r.totalMemory(); long maxmem = r.maxMemory(); long freemem = r.freeMemory(); // @REVIEW // If maximum is not defined...limit to 1G if (maxmem == java.lang.Long.MAX_VALUE) { maxmem = 1024 * 1024 * 1024; } long availmem = maxmem - (totalmem - freemem); // Now determine the dynamic threshold int dynamicThreshold = (int) availmem / (THRESHOLD_FACTOR * inflight); // If it appears that we might run out of memory with this // threshold, reduce the threshold size. if (dynamicThreshold < configThreshold) { if (log.isDebugEnabled()) { log.debug("Using Runtime Attachment File Threshold " + dynamicThreshold); log.debug("maxmem = " + maxmem); log.debug("totalmem = " + totalmem); log.debug("freemem = " + freemem); log.debug("availmem = " + availmem); } } else { dynamicThreshold = configThreshold; if (log.isDebugEnabled()) { log.debug("Using Configured Attachment File Threshold " + configThreshold); log.debug("maxmem = " + maxmem); log.debug("totalmem = " + totalmem); log.debug("freemem = " + freemem); log.debug("availmem = " + availmem); } } return dynamicThreshold; }
From source file:org.b3log.latke.servlet.HTTPRequestDispatcher.java
/** * Dispatches with the specified context. * /*from w w w . j a v a2 s. c o m*/ * @param context the specified specified context * @throws ServletException servlet exception * @throws IOException io exception */ public static void dispatch(final HTTPRequestContext context) throws ServletException, IOException { final HttpServletRequest request = context.getRequest(); String requestURI = (String) request.getAttribute(Keys.HttpRequest.REQUEST_URI); if (Strings.isEmptyOrNull(requestURI)) { requestURI = request.getRequestURI(); } String method = (String) request.getAttribute(Keys.HttpRequest.REQUEST_METHOD); if (Strings.isEmptyOrNull(method)) { method = request.getMethod(); } LOGGER.log(Level.FINER, "Request[requestURI={0}, method={1}]", new Object[] { requestURI, method }); try { final Object processorMethodRet = RequestProcessors.invoke(requestURI, Latkes.getContextPath(), method, context); } catch (final Exception e) { final String exceptionTypeName = e.getClass().getName(); LOGGER.log(Level.FINER, "Occured error while processing request[requestURI={0}, method={1}, exceptionTypeName={2}, errorMsg={3}]", new Object[] { requestURI, method, exceptionTypeName, e.getMessage() }); if ("com.google.apphosting.api.ApiProxy$OverQuotaException".equals(exceptionTypeName)) { PageCaches.removeAll(); context.getResponse().sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); return; } throw new ServletException(e); } catch (final Error e) { final Runtime runtime = Runtime.getRuntime(); LOGGER.log(Level.FINER, "Memory status[total={0}, max={1}, free={2}]", new Object[] { runtime.totalMemory(), runtime.maxMemory(), runtime.freeMemory() }); LOGGER.log(Level.SEVERE, e.getMessage(), e); throw e; } // XXX: processor method ret? final HttpServletResponse response = context.getResponse(); if (response.isCommitted()) { // Sends rdirect or send error final PrintWriter writer = response.getWriter(); writer.flush(); writer.close(); return; } AbstractHTTPResponseRenderer renderer = context.getRenderer(); if (null == renderer) { renderer = new HTTP404Renderer(); } renderer.render(context); }
From source file:ninja.undertow.Benchmarker.java
static public void logMemory() { //Getting the runtime reference from system Runtime runtime = Runtime.getRuntime(); log.info("##### Heap utilization statistics [MB] #####"); //Print used memory log.info("Used Memory:" + (runtime.totalMemory() - runtime.freeMemory())); //Print free memory log.info("Free Memory:" + runtime.freeMemory()); //Print total available memory log.info("Total Memory:" + runtime.totalMemory()); //Print Maximum available memory log.info("Max Memory:" + runtime.maxMemory()); }