List of usage examples for java.lang.management RuntimeMXBean getName
public String getName();
From source file:Test.java
public static void main(String[] args) { RuntimeMXBean mxBean = ManagementFactory.getPlatformMXBean(RuntimeMXBean.class); System.out.println("JVM Name: " + mxBean.getName()); System.out.println("JVM Specification Name: " + mxBean.getSpecName()); System.out.println("JVM Specification Version: " + mxBean.getSpecVersion()); System.out.println("JVM Implemenation Name: " + mxBean.getVmName()); System.out.println("JVM Implemenation Vendor: " + mxBean.getVmVendor()); System.out.println("JVM Implemenation Version: " + mxBean.getVmVersion()); // Using the getPlatformMXBeans method List<OperatingSystemMXBean> list = ManagementFactory.getPlatformMXBeans(OperatingSystemMXBean.class); System.out.println("size: " + list.size()); for (OperatingSystemMXBean bean : list) { System.out.println("Operating System Name: " + bean.getName()); System.out.println("Operating System Architecture: " + bean.getArch()); System.out.println("Operating System Version: " + bean.getVersion()); }//from ww w. java 2 s .c o m }
From source file:it.isislab.dmason.util.SystemManagement.Worker.thrower.DMasonWorker.java
public static void main(String[] args) { RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean(); ////from w w w . ja v a 2 s. c o m // Get name representing the running Java virtual machine. // It returns something like 6460@AURORA. Where the value // before the @ symbol is the PID. // String jvmName = bean.getName(); //Used for log4j properties System.setProperty("logfile.name", "worker" + jvmName); //Used for log4j properties System.setProperty("steplog.name", "workerStep" + jvmName); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss_SS"); Date date = new Date(); dateFormat.format(date); System.setProperty("timestamp", date.toLocaleString()); System.setProperty("paramsfile.name", "params"); try { File logPath = new File("Logs/workers"); if (logPath.exists()) FileUtils.cleanDirectory(logPath); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } logger = Logger.getLogger(DMasonWorker.class.getCanonicalName()); logger.debug("StartWorker " + version); autoStart = false; connect = false; ip = null; port = null; String topic = ""; updated = false; isBatch = false; topicPrefix = ""; if (args.length == 0) { // Force waiting for beacon (requires ActiveMQWrapper) autoStart = false; connect = true; } else if (args.length == 2) { // Launched with IP and Port ip = args[0]; port = args[1]; autoStart = true; connect = true; } else if (args.length == 4) { // Used by D-Mason in order to restart a // worker after update, batch execution, reset autoStart = true; ip = args[0]; port = args[1]; topic = args[2]; if (args[3].equals("update")) { updated = true; } if (args[3].equals("reset")) { updated = false; isBatch = false; } if (args[3].contains("Batch")) { updated = false; isBatch = true; topicPrefix = args[3]; } } else { System.out.println("Usage: StartWorker IP PORT"); } DMasonWorker worker = new DMasonWorker(ip, port, topic); boolean connected = worker.startConnection(); if (connected) { logger.debug("CONNECTED:"); logger.debug(" IP : " + worker.ipAddress.getIPaddress()); logger.debug(" Port : " + worker.ipAddress.getPort()); logger.debug(" Prefix : " + DMasonWorker.topicPrefix); logger.debug(" Topic : " + worker.myTopic); } else { logger.info("CONNECTION FAILED:"); logger.debug(" IP : " + worker.ipAddress.getIPaddress()); logger.debug(" Port : " + worker.ipAddress.getPort()); logger.debug(" Prefix : " + DMasonWorker.topicPrefix); logger.debug(" Topic : " + worker.myTopic); } }
From source file:it.isislab.dmason.util.SystemManagement.Worker.thrower.DMasonWorkerWithGui.java
public static void main(String[] args) { RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean(); ////from w w w. j a v a2 s.com // Get name representing the running Java virtual machine. // It returns something like 6460@AURORA. Where the value // before the @ symbol is the PID. // String jvmName = bean.getName(); //Used for log4j properties System.setProperty("logfile.name", "worker" + jvmName); //Used for log4j properties System.setProperty("steplog.name", "workerStep" + jvmName); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss_SS"); Date date = new Date(); dateFormat.format(date); System.setProperty("timestamp", date.toLocaleString()); System.setProperty("paramsfile.name", "params"); try { File logPath = new File("Logs/workers"); if (logPath.exists()) FileUtils.cleanDirectory(logPath); } catch (IOException e) { //not a problem } logger = Logger.getLogger(DMasonWorker.class.getCanonicalName()); logger.debug("StartWorker " + VERSION); autoStart = false; String ip = null; String port = null; String topic = ""; updated = false; isBatch = false; topicPrefix = ""; // ip, post, autoconnect if (args.length == 3) { ip = args[0]; port = args[1]; if (args[2].equals("autoconnect")) { autoStart = true; } } // ip, post, topic, event if (args.length == 4) { autoStart = true; if (args[3].equals("update")) { updated = true; } if (args[3].equals("reset")) { updated = false; isBatch = false; } if (args[3].contains("Batch")) { updated = false; isBatch = true; topicPrefix = args[3]; } ip = args[0]; port = args[1]; topic = args[2]; } /*if(args.length == 2 && args[0].equals("auto")) { autoStart = true; updated = true; topic = args[1]; } if(args.length == 1 && args[0].equals("auto")) { autoStart = true; }*/ new DMasonWorkerWithGui(autoStart, updated, isBatch, topic, ip, port); }
From source file:Main.java
public static long getPid() { RuntimeMXBean mx = ManagementFactory.getRuntimeMXBean(); String[] mxNameTable = mx.getName().split("@"); //$NON-NLS-1$ if (mxNameTable.length == 2) { return Long.parseLong(mxNameTable[0]); } else {// w w w. j a v a 2 s.co m return Thread.currentThread().getId(); } }
From source file:jetbrains.exodus.util.ForkedProcessRunner.java
private static String getProcessId() { RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); String name = runtimeBean.getName(); return name.substring(0, name.indexOf('@')); // yes, it's not documented, but name has form "PID@bullshit" }
From source file:com.hp.mqm.atrf.Main.java
private static void configureLog4J() { //set process Id on local RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean(); String pid = rt.getName(); ThreadContext.put("PID", pid); String log4jConfiguration = System.getProperty("log4j.configuration"); if (StringUtils.isEmpty(log4jConfiguration)) { //try to take from file File f = new File("log4j2.xml"); URI uri = null;// w w w. jav a2 s . com if (f.exists() && !f.isDirectory() && f.canRead()) { uri = f.toURI(); } else { //take it from resources try { uri = Main.class.getClassLoader().getResource("log4j2.xml").toURI(); } catch (URISyntaxException e) { logger.info("Failed to load Log4j configuration from resource file"); } } LoggerContext context = (LoggerContext) LogManager.getContext(false); context.setConfigLocation(uri); //logger.info("Log4j configuration loaded from " + uri.toString()); } else { logger.info("Log4j configuration is loading from log4j.configuration=" + log4jConfiguration); } }
From source file:com.jredrain.startup.Bootstrap.java
private static int getPid() { RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); String name = runtime.getName(); try {/*w w w .j av a2s.co m*/ return Integer.parseInt(name.substring(0, name.indexOf('@'))); } catch (Exception e) { } return -1; }
From source file:com.yahoo.dba.tools.myperfserver.App.java
/** * Get process id of current running starloader * @return OS process id//from ww w . j ava 2 s .c o m */ public static int getPid() { try { RuntimeMXBean rt = java.lang.management.ManagementFactory.getRuntimeMXBean(); String jvmName = rt.getName(); String ss = jvmName.substring(0, jvmName.indexOf('@')); return Integer.parseInt(ss); } catch (Exception ex) { ex.printStackTrace(); } return -1;//no valid number }
From source file:com.smartmarmot.dbforbix.DBforBix.java
public static void writePid(String _pidfile) throws Exception { RuntimeMXBean rmxb = ManagementFactory.getRuntimeMXBean(); String pid = rmxb.getName(); try {/*from ww w . ja v a 2s . c om*/ File target = new File(_pidfile); File newTarget = new File(target.getAbsoluteFile().getCanonicalPath()); target = null; if (newTarget.exists()) { boolean success = newTarget.delete(); if (!success) { DBforBix.LOG.log(Level.ERROR, "Delete: deletion failed " + newTarget.getAbsolutePath()); } } if (!newTarget.exists()) { FileOutputStream fout = new FileOutputStream(newTarget); new PrintStream(fout).print(pid); fout.close(); } } catch (IOException e) { DBforBix.LOG.log(Level.ERROR, "Unable to write to file " + _pidfile + " error:" + e); } }
From source file:de.unisb.cs.st.javalanche.mutation.runtime.jmx.MutationMxClient.java
public static boolean connect(int i) { JMXConnector jmxc = null;// ww w . ja v a2 s .c om JMXServiceURL url = null; try { url = new JMXServiceURL(MXBeanRegisterer.ADDRESS + i); jmxc = JMXConnectorFactory.connect(url, null); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { return false; // System.out.println("Could not connect to address: " + url); // e.printStackTrace(); } if (jmxc != null) { try { MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); ObjectName objectName = new ObjectName(MXBeanRegisterer.OBJECT_NAME); Object numberOfMutations = mbsc.getAttribute(objectName, "NumberOfMutations"); Object currentTest = mbsc.getAttribute(objectName, "CurrentTest"); Object currentMutation = mbsc.getAttribute(objectName, "CurrentMutation"); Object allMutations = mbsc.getAttribute(objectName, "Mutations"); Object mutationsDuration = mbsc.getAttribute(objectName, "MutationDuration"); Object testDuration = mbsc.getAttribute(objectName, "TestDuration"); // Object mutationSummary = mbsc.getAttribute(objectName, // "MutationSummary"); final RuntimeMXBean remoteRuntime = ManagementFactory.newPlatformMXBeanProxy(mbsc, ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class); final MemoryMXBean remoteMemory = ManagementFactory.newPlatformMXBeanProxy(mbsc, ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class); System.out.print("Connection: " + i + " "); System.out.println("Target VM: " + remoteRuntime.getName() + " - " + remoteRuntime.getVmVendor() + " - " + remoteRuntime.getSpecVersion() + " - " + remoteRuntime.getVmVersion()); System.out.println( "Running for: " + DurationFormatUtils.formatDurationHMS(remoteRuntime.getUptime())); System.out .println("Memory usage: Heap - " + formatMemory(remoteMemory.getHeapMemoryUsage().getUsed()) + " Non Heap - " + formatMemory(remoteMemory.getNonHeapMemoryUsage().getUsed())); String mutationDurationFormatted = DurationFormatUtils .formatDurationHMS(Long.parseLong(mutationsDuration.toString())); String testDurationFormatted = DurationFormatUtils .formatDurationHMS(Long.parseLong(testDuration.toString())); if (DEBUG_ADD) { System.out.println("Classpath: " + remoteRuntime.getClassPath()); System.out.println("Args: " + remoteRuntime.getInputArguments()); System.out.println("All Mutations: " + allMutations); } // System.out.println(mutationSummary); System.out.println( "Current mutation (Running for: " + mutationDurationFormatted + "): " + currentMutation); System.out.println("Mutations tested: " + numberOfMutations); System.out.println("Current test: (Running for: " + testDurationFormatted + "): " + currentTest); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (MalformedObjectNameException e) { e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); } catch (AttributeNotFoundException e) { e.printStackTrace(); } catch (InstanceNotFoundException e) { e.printStackTrace(); } catch (MBeanException e) { e.printStackTrace(); } catch (ReflectionException e) { e.printStackTrace(); } finally { try { jmxc.close(); } catch (IOException e) { e.printStackTrace(); } } } return true; }