src/share/classes/sun/tools/jps/Jps.java

Print this page
rev 8717 : 8027765: Make exit codes and stdout/stderr printing from jmap/jinfo/jstack/jps consistent
Reviewed-by:


  28 import java.util.*;
  29 import java.net.*;
  30 import sun.jvmstat.monitor.*;
  31 
  32 /**
  33  * Application to provide a listing of monitorable java processes.
  34  *
  35  * @author Brian Doherty
  36  * @since 1.5
  37  */
  38 public class Jps {
  39 
  40     private static Arguments arguments;
  41 
  42     public static void main(String[] args) {
  43         try {
  44             arguments = new Arguments(args);
  45         } catch (IllegalArgumentException e) {
  46             System.err.println(e.getMessage());
  47             Arguments.printUsage(System.err);
  48             return;
  49         }
  50 
  51         if (arguments.isHelp()) {
  52             Arguments.printUsage(System.out);
  53             System.exit(0);
  54         }
  55 
  56         try {
  57             HostIdentifier hostId = arguments.hostId();
  58             MonitoredHost monitoredHost =
  59                     MonitoredHost.getMonitoredHost(hostId);
  60 
  61             // get the set active JVMs on the specified host.
  62             Set<Integer> jvms = monitoredHost.activeVms();
  63 
  64             for (Integer jvm: jvms) {
  65                 StringBuilder output = new StringBuilder();
  66                 Throwable lastError = null;
  67 
  68                 int lvmid = jvm;
  69 
  70                 output.append(String.valueOf(lvmid));
  71 
  72                 if (arguments.isQuiet()) {


 148                         }
 149                         System.out.println(output);
 150                         if (arguments.printStackTrace()) {
 151                             lastError.printStackTrace();
 152                         }
 153                         continue;
 154                     }
 155                 }
 156             }
 157         } catch (MonitorException e) {
 158             if (e.getMessage() != null) {
 159                 System.err.println(e.getMessage());
 160             } else {
 161                 Throwable cause = e.getCause();
 162                 if ((cause != null) && (cause.getMessage() != null)) {
 163                     System.err.println(cause.getMessage());
 164                 } else {
 165                     e.printStackTrace();
 166                 }
 167             }

 168         }
 169     }
 170 }


  28 import java.util.*;
  29 import java.net.*;
  30 import sun.jvmstat.monitor.*;
  31 
  32 /**
  33  * Application to provide a listing of monitorable java processes.
  34  *
  35  * @author Brian Doherty
  36  * @since 1.5
  37  */
  38 public class Jps {
  39 
  40     private static Arguments arguments;
  41 
  42     public static void main(String[] args) {
  43         try {
  44             arguments = new Arguments(args);
  45         } catch (IllegalArgumentException e) {
  46             System.err.println(e.getMessage());
  47             Arguments.printUsage(System.err);
  48             System.exit(1);
  49         }
  50 
  51         if (arguments.isHelp()) {
  52             Arguments.printUsage(System.err);
  53             System.exit(0);
  54         }
  55 
  56         try {
  57             HostIdentifier hostId = arguments.hostId();
  58             MonitoredHost monitoredHost =
  59                     MonitoredHost.getMonitoredHost(hostId);
  60 
  61             // get the set active JVMs on the specified host.
  62             Set<Integer> jvms = monitoredHost.activeVms();
  63 
  64             for (Integer jvm: jvms) {
  65                 StringBuilder output = new StringBuilder();
  66                 Throwable lastError = null;
  67 
  68                 int lvmid = jvm;
  69 
  70                 output.append(String.valueOf(lvmid));
  71 
  72                 if (arguments.isQuiet()) {


 148                         }
 149                         System.out.println(output);
 150                         if (arguments.printStackTrace()) {
 151                             lastError.printStackTrace();
 152                         }
 153                         continue;
 154                     }
 155                 }
 156             }
 157         } catch (MonitorException e) {
 158             if (e.getMessage() != null) {
 159                 System.err.println(e.getMessage());
 160             } else {
 161                 Throwable cause = e.getCause();
 162                 if ((cause != null) && (cause.getMessage() != null)) {
 163                     System.err.println(cause.getMessage());
 164                 } else {
 165                     e.printStackTrace();
 166                 }
 167             }
 168             System.exit(1);
 169         }
 170     }
 171 }