Java Code Examples for java.lang.management.RuntimeMXBean#getName()

The following examples show how to use java.lang.management.RuntimeMXBean#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Test7194254.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static String getPid() {
    RuntimeMXBean runtimebean = ManagementFactory.getRuntimeMXBean();
    String vmname = runtimebean.getName();
    int i = vmname.indexOf('@');
    if (i != -1) {
        vmname = vmname.substring(0, i);
    }
    return vmname;
}
 
Example 2
Source File: TestThreadDumpMonitorContention.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
static String getPid() {
    RuntimeMXBean runtimebean = ManagementFactory.getRuntimeMXBean();
    String vmname = runtimebean.getName();
    int i = vmname.indexOf('@');
    if (i != -1) {
        vmname = vmname.substring(0, i);
    }
    return vmname;
}
 
Example 3
Source File: Test7194254.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
static String getPid() {
    RuntimeMXBean runtimebean = ManagementFactory.getRuntimeMXBean();
    String vmname = runtimebean.getName();
    int i = vmname.indexOf('@');
    if (i != -1) {
        vmname = vmname.substring(0, i);
    }
    return vmname;
}
 
Example 4
Source File: NodeHelper.java    From TarsJava with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private int getPid() {
    RuntimeMXBean rmxb = ManagementFactory.getRuntimeMXBean();
    String name = rmxb.getName();
    int pid = -1;
    try {
        pid = Integer.parseInt(name.split("@")[0]);
    } catch (Throwable t) {
    }
    return pid;
}
 
Example 5
Source File: TestThreadDumpMonitorContention.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static String getPid() {
    RuntimeMXBean runtimebean = ManagementFactory.getRuntimeMXBean();
    String vmname = runtimebean.getName();
    int i = vmname.indexOf('@');
    if (i != -1) {
        vmname = vmname.substring(0, i);
    }
    return vmname;
}
 
Example 6
Source File: JobNodeConfigFactory.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
private static Integer getPid() {
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    String name = runtime.getName();
    int index = name.indexOf("@");
    if (index != -1) {
        return Integer.parseInt(name.substring(0, index));
    }
    return 0;
}
 
Example 7
Source File: ConfigUtils.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public static int getPid() {
    if (PID < 0) {
        try {
            RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();  
            String name = runtime.getName(); // format: "pid@hostname"  
            PID = Integer.parseInt(name.substring(0, name.indexOf('@')));
        } catch (Throwable e) {
            PID = 0;
        }
    }
    return PID;  
}
 
Example 8
Source File: JobXAgent.java    From JobX with Apache License 2.0 5 votes vote down vote up
private static Integer getPid() {
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    String name = runtime.getName();
    try {
        return Integer.parseInt(name.substring(0, name.indexOf('@')));
    } catch (Exception e) {
    }
    return -1;
}
 
Example 9
Source File: ConfigUtils.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static int getPid() {
    if (PID < 0) {
        try {
            RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();  
            String name = runtime.getName(); // format: "pid@hostname"  
            PID = Integer.parseInt(name.substring(0, name.indexOf('@')));
        } catch (Throwable e) {
            PID = 0;
        }
    }
    return PID;  
}
 
Example 10
Source File: TestThreadDumpMonitorContention.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static String getPid() {
    RuntimeMXBean runtimebean = ManagementFactory.getRuntimeMXBean();
    String vmname = runtimebean.getName();
    int i = vmname.indexOf('@');
    if (i != -1) {
        vmname = vmname.substring(0, i);
    }
    return vmname;
}
 
Example 11
Source File: UtilAll.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
public static int getPid() {
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    String name = runtime.getName(); // format: "pid@hostname"
    try {
        return Integer.parseInt(name.substring(0, name.indexOf('@')));
    } catch (Exception e) {
        return -1;
    }
}
 
Example 12
Source File: ConfigUtils.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static int getPid() {
    if (PID < 0) {
        try {
            RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();  
            String name = runtime.getName(); // format: "pid@hostname"  
            PID = Integer.parseInt(name.substring(0, name.indexOf('@')));
        } catch (Throwable e) {
            PID = 0;
        }
    }
    return PID;  
}
 
Example 13
Source File: UtilAll.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
public static int getPid() {
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    String name = runtime.getName(); // format: "pid@hostname"
    try {
        return Integer.parseInt(name.substring(0, name.indexOf('@')));
    }
    catch (Exception e) {
        return -1;
    }
}
 
Example 14
Source File: UtilAll.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public static int getPid() {
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();        
    String name = runtime.getName(); // format: "pid@hostname"
    try {
        return Integer.parseInt(name.substring(0, name.indexOf('@')));
    } catch (Exception e) {
        return -1;
    }
}
 
Example 15
Source File: ProcessInfo.java    From Mycat-openEP with Apache License 2.0 5 votes vote down vote up
private static void extractPID(){
	RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();  
       String name = runtime.getName(); // format: "pid@hostname"  
       try {  
           PID_TEXT=name.substring(0, name.indexOf('@'));  
       } catch (Exception e) {  
           PID_TEXT="-1";  
       }
}
 
Example 16
Source File: DBforBix.java    From DBforBIX with GNU General Public License v3.0 5 votes vote down vote up
public static void writePid(String _pidfile) throws Exception {
	RuntimeMXBean rmxb = ManagementFactory.getRuntimeMXBean();
	String pid = rmxb.getName();
	try {
		
		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);
	}
}
 
Example 17
Source File: Test7194254.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
static String getPid() {
    RuntimeMXBean runtimebean = ManagementFactory.getRuntimeMXBean();
    String vmname = runtimebean.getName();
    int i = vmname.indexOf('@');
    if (i != -1) {
        vmname = vmname.substring(0, i);
    }
    return vmname;
}
 
Example 18
Source File: ForkedProcessRunner.java    From xodus with Apache License 2.0 4 votes vote down vote up
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"
}
 
Example 19
Source File: Handler.java    From cloudsync with GNU General Public License v2.0 4 votes vote down vote up
public void init(SyncType synctype, String cacheFile, String lockFile, String pidFile, boolean nocache, boolean forcestart) throws CloudsyncException
{
	cacheFilePath = Paths.get(cacheFile.replace("{name}", name));
	lockFilePath = Paths.get(lockFile.replace("{name}", name));
	pidFilePath = Paths.get(pidFile.replace("{name}", name));

	if (synctype.checkPID())
	{
		if (!forcestart && Files.exists(pidFilePath, LinkOption.NOFOLLOW_LINKS))
		{
			throw new CloudsyncException(
					"Other job is running or previous job has crashed. If you are sure that no other job is running use the option '--forcestart'");
		}

		RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
		String jvmName = bean.getName();
		long pid = Long.valueOf(jvmName.split("@")[0]);

		try
		{
			Files.write(pidFilePath, Long.toString(pid).getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
			pidCleanup = true;
		}
		catch (IOException e)
		{
			throw new CloudsyncException("Couldn't create '" + pidFilePath.toString() + "'");
		}
	}

	if (Files.exists(lockFilePath, LinkOption.NOFOLLOW_LINKS))
	{
		LOGGER.log(Level.WARNING,
				"Found an inconsistent cache file state. Possibly previous job has crashed or duplicate files was detected. Force a cache file rebuild.");
		nocache = true;
	}

	if (!nocache && Files.exists(cacheFilePath, LinkOption.NOFOLLOW_LINKS))
	{
		LOGGER.log(Level.INFO, "load structure from cache file");
		readCSVStructure(cacheFilePath);
	}
	else
	{
		LOGGER.log(Level.INFO, "load structure from remote server");
		createLock();
		readRemoteStructure(root);
	}
	releaseLock();
}
 
Example 20
Source File: Util.java    From radar with Apache License 2.0 4 votes vote down vote up
/**
 * 获取进程Id
 *
 * @return
 */
public static Integer getProcessId() {
	RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
	String name = runtime.getName();
	return Integer.parseInt(name.substring(0, name.indexOf("@")));
}