/**
* Gets all threads in the JVM. This is really a snapshot of all threads at the time this method is called.
* @return An array of all threads currently running in the JVM.
*/
static public Thread[] getAllThreads(){
final ThreadGroup root=getRootThreadGroup();
final ThreadMXBean thbean=ManagementFactory.getThreadMXBean();
int nAlloc=thbean.getThreadCount();
int n=0;
Thread[] threads;
do {
nAlloc*=2;
threads=new Thread[nAlloc];
n=root.enumerate(threads,true);
}
while (n == nAlloc);
return java.util.Arrays.copyOf(threads,n);
}

Example 17

From project cloudhopper-smpp, under directory /src/main/java/com/cloudhopper/smpp/impl/.

/**
* Register the given mbean with the platform mbean server, unregistering any mbean that was there before. Note, this method will not throw an exception if the registration fails (since there is nothing you can do and it isn't fatal), instead it just returns false indicating the registration failed.
* @param mbean The object to register as an mbean
* @param name The name to register this mbean with
* @returns true if the registration succeeded
*/
static boolean registerMBean(Object mbean,String name){
try {
MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
synchronized (mbs) {
ObjectName objName=new ObjectName(name);
if (mbs.isRegistered(objName)) {
mbs.unregisterMBean(objName);
}
mbs.registerMBean(mbean,objName);
}
return true;
}
catch ( Exception e) {
e.printStackTrace();
}
return false;
}

Example 48

From project jagger, under directory /diagnostics/src/main/java/com/griddynamics/jagger/diagnostics/thread/sampling/.