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

The following examples show how to use java.lang.management.RuntimeMXBean#getStartTime() . 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: FileJavaScriptHandler.java    From validator-web with Apache License 2.0 6 votes vote down vote up
@Override
protected long getLastModifiedTime() {
    try {
        URL url = ResourceUtils.getResourceAsUrl(resource);
        if ("file".equals(url.getProtocol())) {
            File file = new File(url.getFile());
            return file.lastModified();
        }
    } catch (IOException ex) {
        // ignore
    }
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    long startTime = runtimeMXBean.getStartTime();
    // Container start time (browsers are only accurate to the second)
    return startTime - (startTime % 1000);
}
 
Example 2
Source File: KeepAliveHandler.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static String humanReadableUptime() {
	RuntimeMXBean mxBean = ManagementFactory.getRuntimeMXBean();
	Interval interval = new Interval(mxBean.getStartTime(), System.currentTimeMillis());
	Period period = interval.toPeriod();

	return String.format("%d months, %d days, %d hours, %d minutes, %d seconds%n", period.getMonths(), period.getDays(), period.getHours(), period.getMinutes(), period.getSeconds());
}
 
Example 3
Source File: NetworkInfo.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String getUptime() {
	RuntimeMXBean mxBean = ManagementFactory.getRuntimeMXBean();
	Interval interval = new Interval(mxBean.getStartTime(), System.currentTimeMillis());
	Period period = interval.toPeriod();

	return String.format("%d months, %d days, %d hours, %d minutes, %d seconds%n", period.getMonths(), period.getDays(), period.getHours(), period.getMinutes(), period.getSeconds());
}
 
Example 4
Source File: GeneratedValidationJavaScriptHandler.java    From validator-web with Apache License 2.0 5 votes vote down vote up
@Override
protected long getLastModifiedTime() {
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    long startTime = runtimeMXBean.getStartTime();
    // Container start time (browsers are only accurate to the second)
    return startTime - (startTime % 1000);
}
 
Example 5
Source File: KeepAliveHandler.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static String humanReadableUptime() {
	RuntimeMXBean mxBean = ManagementFactory.getRuntimeMXBean();
	Interval interval = new Interval(mxBean.getStartTime(), System.currentTimeMillis());
	Period period = interval.toPeriod();

	return String.format("%d months, %d days, %d hours, %d minutes, %d seconds%n", period.getMonths(), period.getDays(), period.getHours(), period.getMinutes(), period.getSeconds());
}
 
Example 6
Source File: NetworkInfo.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String getUptime() {
	RuntimeMXBean mxBean = ManagementFactory.getRuntimeMXBean();
	Interval interval = new Interval(mxBean.getStartTime(), System.currentTimeMillis());
	Period period = interval.toPeriod();

	return String.format("%d months, %d days, %d hours, %d minutes, %d seconds%n", period.getMonths(), period.getDays(), period.getHours(), period.getMinutes(), period.getSeconds());
}
 
Example 7
Source File: JMServer.java    From jmonitor with GNU General Public License v2.0 5 votes vote down vote up
@HttpMapping(url = "/loadRuntimeInfo")
public JSONObject doLoadRuntimeInfo(Map<String, Object> param) {
    try {
        String app = ((HttpServletRequest) param.get(JMDispatcher.REQ)).getParameter("app");
        RuntimeMXBean mBean = JMConnManager.getRuntimeMBean(app);
        ClassLoadingMXBean cBean = JMConnManager.getClassMbean(app);
        Map<String, String> props = mBean.getSystemProperties();
        DateFormat format = DateFormat.getInstance();
        List<String> input = mBean.getInputArguments();
        Date date = new Date(mBean.getStartTime());

        TreeMap<String, Object> data = new TreeMap<String, Object>();

        data.put("apppid", mBean.getName());
        data.put("startparam", input.toString());
        data.put("starttime", format.format(date));
        data.put("classLoadedNow", cBean.getLoadedClassCount());
        data.put("classUnloadedAll", cBean.getUnloadedClassCount());
        data.put("classLoadedAll", cBean.getTotalLoadedClassCount());
        data.putAll(props);

        JSONObject json = new JSONObject(true);
        json.putAll(data);
        return json;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 8
Source File: JvmPropertyProvider.java    From appstatus with Apache License 2.0 5 votes vote down vote up
public Map<String, String> getProperties() {
    Map<String, String> map = new TreeMap<String, String>();
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();

    List<String> aList = runtimeMXBean.getInputArguments();
    String parameters = "";
    for (int i = 0; i < aList.size(); i++) {
        parameters = parameters + " " + aList.get(i);
    }
    map.put("params", parameters);

    map.put("name", runtimeMXBean.getVmName());
    map.put("vendor", runtimeMXBean.getVmVendor());
    map.put("version", runtimeMXBean.getVmVersion());
    map.put("specification", runtimeMXBean.getSpecVersion());
    map.put("uptime", DurationFormatUtils.formatDurationHMS(runtimeMXBean.getUptime()));

    Date date = new Date(runtimeMXBean.getStartTime());
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
    map.put("start time", sdf.format(date));

    MemoryMXBean memory = ManagementFactory.getMemoryMXBean();

    MemoryUsage heap = memory.getHeapMemoryUsage();
    map.put("memory. (heap)", readableFileSize(heap.getUsed()) + "/" + readableFileSize(heap.getCommitted()) + " min:" + readableFileSize(heap.getInit()) + " max:" + readableFileSize(heap.getMax()));
    MemoryUsage nonheap = memory.getNonHeapMemoryUsage();
    map.put("memory (non heap)", readableFileSize(nonheap.getUsed()) + "/" + readableFileSize(nonheap.getCommitted()) + " min:" + readableFileSize(nonheap.getInit()) + " max:" + readableFileSize(nonheap.getMax()));

    return map;
}
 
Example 9
Source File: HeatBeatRecordHelper.java    From smart-admin with MIT License 4 votes vote down vote up
/**
 * 获取进程启动时间
 * @return
 */
public static final Date getStartTime(){
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    return new Date(runtimeMXBean.getStartTime());
}
 
Example 10
Source File: Platform.java    From zstack with Apache License 2.0 4 votes vote down vote up
public static boolean isAfterManagementNodeStart(Timestamp ts) {
    RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
    Timestamp startMnTime = new Timestamp(bean.getStartTime());
    return ts.after(startMnTime);
}
 
Example 11
Source File: Controller.java    From floodlight_with_topoguard with Apache License 2.0 4 votes vote down vote up
@Override
public long getSystemStartTime() {
    RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean();
    return rb.getStartTime();
}
 
Example 12
Source File: IngestionHealthCheck.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
public String getStartTime() {
    //Start Time
    RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
    long startTimeLong = bean.getStartTime();
    return convertEpochTimeToDateTime(startTimeLong);
}