public List < ProcessDescription > listProcesses ( ) throws NoSuchMethodException , InvocationTargetException , IllegalAccessException { List < ProcessDescription > ret = new ArrayList < ProcessDescription > ( ) ; Class vmClass = lookupVirtualMachineClass ( ) ; Method method = vmClass . getMethod ( "list" ) ; List vmDescriptors = ( List ) method . invoke ( null ) ; for ( Object descriptor : vmDescriptors ) { Method idMethod = descriptor . getClass ( ) . getMethod ( "id" ) ; String id = ( String ) idMethod . invoke ( descriptor ) ; Method displayMethod = descriptor . getClass ( ) . getMethod ( "displayName" ) ; String display = ( String ) displayMethod . invoke ( descriptor ) ; ret . add ( new ProcessDescription ( id , display ) ) ; } return ret ; }
Return a list of all Java processes