public static double getCpuUsage(long time) throws ApplicationException { if (time < 1) throw new ApplicationException("time has to be bigger than 0"); if (jsm == null) jsm = new JavaSysMon(); CpuTimes cput = jsm.cpuTimes(); if (cput == null) throw new ApplicationException("CPU information are not available for this OS"); CpuTimes previous = new CpuTimes(cput.getUserMillis(), cput.getSystemMillis(), cput.getIdleMillis()); sleep(time); return jsm.cpuTimes().getCpuUsage(previous) * 100D; }
public void run() { PageContextImpl pci = (PageContextImpl) pc; Thread thread = pc.getThread(); pci.stop(t); int count = 0; if (thread.isAlive()) { do { if (count > 0 && log != null) { LogUtil.log( log, Log.LEVEL_ERROR, "", "could not stop the thread on the first approach", thread.getStackTrace()); } if (count++ > 10) break; // should never happen try { thread.stop(t); } catch (UnsupportedOperationException uoe) { LogUtil.log( log, Log.LEVEL_ERROR, "", "Thread.stop(Throwable) is not supported by this JVM and failed with UnsupportedOperationException", thread.getStackTrace()); thread.stop(); } SystemUtil.sleep(1000); } while (thread.isAlive() && pci.isInitialized()); } if (count > 10 && log != null) { LogUtil.log(log, Log.LEVEL_ERROR, "", "could not stop the thread", thread.getStackTrace()); aprint.e(thread.getStackTrace()); } }
@Override public void run() { // scheduleThread.start(); boolean firstRun = true; List<ControlerThread> threads = new ArrayList<ControlerThread>(); CFMLFactoryImpl factories[] = null; while (state.active()) { // sleep SystemUtil.sleep(interval); factories = toFactories(factories, contextes); // start the thread that calls control ControlerThread ct = new ControlerThread(this, factories, firstRun, configServer.getLog("application")); ct.start(); threads.add(ct); if (threads.size() > 10 && lastMinuteInterval + 60000 < System.currentTimeMillis()) configServer .getLog("application") .info("controller", threads.size() + " active controller threads"); // now we check all threads we have Iterator<ControlerThread> it = threads.iterator(); long time; while (it.hasNext()) { ct = it.next(); // print.e(ct.hashCode()); time = System.currentTimeMillis() - ct.start; // done if (ct.done >= 0) { if (time > 10000) configServer .getLog("application") .info("controller", "controler took " + ct.done + "ms to execute sucessfully."); it.remove(); } // failed else if (ct.t != null) { LogUtil.log(configServer.getLog("application"), Log.LEVEL_ERROR, "controler", ct.t); it.remove(); } // stop it! else if (time > TIMEOUT) { SystemUtil.stop(ct); // print.e(ct.getStackTrace()); if (!ct.isAlive()) { configServer .getLog("application") .error( "controller", "controler thread [" + ct.hashCode() + "] forced to stop after " + time + "ms"); it.remove(); } else { LogUtil.log( configServer.getLog("application"), Log.LEVEL_ERROR, "controler", "was not able to stop controller thread running for " + time + "ms", ct.getStackTrace()); } } } if (factories.length > 0) firstRun = false; } }