List of usage examples for java.lang.management ManagementFactory getRuntimeMXBean
public static RuntimeMXBean getRuntimeMXBean()
From source file:org.opencron.agent.Bootstrap.java
private static Integer getPid() { RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); String name = runtime.getName(); try {/*w ww. j a va 2 s . c o m*/ return Integer.parseInt(name.substring(0, name.indexOf('@'))); } catch (Exception e) { } return -1; }
From source file:net.bull.javamelody.internal.model.JavaInformations.java
private static String buildJvmArguments() { final StringBuilder jvmArgs = new StringBuilder(); for (final String jvmArg : ManagementFactory.getRuntimeMXBean().getInputArguments()) { jvmArgs.append(jvmArg).append('\n'); }/*w w w . ja va2 s. co m*/ if (jvmArgs.length() > 0) { jvmArgs.deleteCharAt(jvmArgs.length() - 1); } return jvmArgs.toString(); }
From source file:org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader.java
private static File computeTopCacheDir() { String cacheDirPath = AccumuloClassLoader.getAccumuloString(VFS_CACHE_DIR, System.getProperty("java.io.tmpdir")); String procName = ManagementFactory.getRuntimeMXBean().getName(); return new File(cacheDirPath, "accumulo-vfs-cache-" + procName + "-" + System.getProperty("user.name", "nouser")); }
From source file:com.pianobakery.complsa.MainGui.java
public void runtimeParameters() { RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean(); List<String> aList = bean.getInputArguments(); long heapSize = Runtime.getRuntime().totalMemory(); logger.info("Heap Size = " + heapSize); long heapSizeMax = Runtime.getRuntime().maxMemory(); System.out.println("Heap Size max= " + heapSize); for (int i = 0; i < aList.size(); i++) { logger.info("Runtime Infos: " + aList.get(i)); }/* ww w .j a v a 2 s. c o m*/ }
From source file:com.all.ultrapeer.UltrapeerMonitor.java
private double calculateCpuUsage() throws InterruptedException { OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory .getOperatingSystemMXBean(); RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); int numCpus = operatingSystemMXBean.getAvailableProcessors(); long prevUpTime = runtimeMXBean.getUptime(); long prevProcessCpuTime = operatingSystemMXBean.getProcessCpuTime(); Thread.sleep(500);// w w w . j a v a 2s . co m long upTime = runtimeMXBean.getUptime(); long processCpuTime = operatingSystemMXBean.getProcessCpuTime(); if (prevUpTime > 0L && upTime > prevUpTime) { long elapsedCpu = processCpuTime - prevProcessCpuTime; long elapsedTime = upTime - prevUpTime; return Math.min(99F, elapsedCpu / (elapsedTime * 10000F * numCpus)); } return 0.001; }
From source file:org.jahia.bin.listeners.JahiaContextLoaderListener.java
private static void detectPID(ServletContext servletContext) { try {/*from ww w . j a v a 2 s . co m*/ pid = Patterns.AT.split(ManagementFactory.getRuntimeMXBean().getName())[0]; } catch (Exception e) { logger.warn("Unable to determine process id", e); } }
From source file:org.bonitasoft.engine.test.internal.EngineStarter.java
private void removeLicensesFolderAndDeleteIt(List<File> list) throws IOException { Iterator<File> iterator = list.iterator(); while (iterator.hasNext()) { File tempFolder = iterator.next(); //folder of licenses not deleted because the shutdown hook that delete temp files //is executed as the same time as the shutdown hook that stops the engine if (tempFolder.getName().contains("bonita_engine") && tempFolder.getName().contains(ManagementFactory.getRuntimeMXBean().getName())) { Path licenses = tempFolder.toPath().resolve("licenses"); if (Files.exists(licenses)) { FileUtils.deleteDirectory(licenses.toFile()); }/*from ww w .ja va 2 s. c om*/ if (tempFolder.list().length == 0) { FileUtils.deleteDirectory(tempFolder); //remove this directory because there was only the licenses there iterator.remove(); } } } }
From source file:org.slc.sli.ingestion.processors.ControlFilePreProcessor.java
private void auditSecurityEvent(NewBatchJob currentJob, ControlFile controlFile) { byte[] ipAddr = null; try {//w w w . j a va2s .c om InetAddress addr = InetAddress.getLocalHost(); // Get IP Address ipAddr = addr.getAddress(); } catch (UnknownHostException e) { LogUtil.error(LOG, "Error getting local host", e); } String edOrg = tenantDA.getTenantEdOrg(currentJob.getTopLevelSourceId()); if (edOrg == null) { edOrg = ""; } List<String> userRoles = Collections.emptyList(); SecurityEvent event = new SecurityEvent(); event.setTenantId(controlFile.getConfigProperties().getProperty("tenantId")); event.setUser(""); event.setUserEdOrg(edOrg); event.setTargetEdOrgList(edOrg); //@TA10431 - change targetEdOrg from scalar to list event.setActionUri("processUsingNewBatchJob"); event.setAppId("Ingestion"); event.setOrigin(""); event.setExecutedOn(ipAddr[0] + "." + ipAddr[1] + "." + ipAddr[2] + "." + ipAddr[3]); event.setCredential(""); event.setUserOrigin(""); event.setTimeStamp(new Date()); event.setProcessNameOrId(ManagementFactory.getRuntimeMXBean().getName()); event.setClassName(this.getClass().getName()); event.setLogLevel(LogLevelType.TYPE_INFO); event.setRoles(userRoles); event.setLogMessage("Ingestion process started."); audit(event); }
From source file:com.l2jfree.util.concurrent.L2ThreadPool.java
public static void shutdown() { final long begin = System.currentTimeMillis(); try {/*from www .j a v a 2 s .co m*/ System.out.println("L2ThreadPool: Shutting down."); System.out.println("\t... executing " + getTaskCount(_scheduledPools) + " scheduled tasks."); System.out.println("\t... executing " + getTaskCount(_instantPools) + " instant tasks."); System.out.println("\t... executing " + getTaskCount(_longRunningPools) + " long running tasks."); } catch (Throwable t) { t.printStackTrace(); } try { for (ThreadPoolExecutor threadPool : getThreadPools()) { try { threadPool.shutdown(); } catch (Throwable t) { t.printStackTrace(); } } } catch (Throwable t) { t.printStackTrace(); } boolean success = false; try { success |= awaitTermination(5000); for (ScheduledThreadPoolExecutor scheduledPool : _scheduledPools) { scheduledPool.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); scheduledPool.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); } success |= awaitTermination(10000); } catch (Throwable t) { t.printStackTrace(); } try { System.out.println( "\t... success: " + success + " in " + (System.currentTimeMillis() - begin) + " msec."); System.out.println("\t... " + getTaskCount(_scheduledPools) + " scheduled tasks left."); System.out.println("\t... " + getTaskCount(_instantPools) + " instant tasks left."); System.out.println("\t... " + getTaskCount(_longRunningPools) + " long running tasks left."); if (TimeUnit.MINUTES.toMillis(30) < ManagementFactory.getRuntimeMXBean().getUptime()) RunnableStatsManager.dumpClassStats(SortBy.TOTAL); } catch (Throwable t) { t.printStackTrace(); } }
From source file:org.mitre.provenance.capture.linux.PROCtor.java
/** * Return the PID of the process that PROCtor is running underneath. * @return/*from w w w. jav a2 s . c o m*/ */ public static String getMyPID() { String pidStr = ManagementFactory.getRuntimeMXBean().getName(); int idx = pidStr.indexOf("@"); if (idx == -1) return pidStr; else return pidStr.substring(0, idx); }