(VMDetailView view)
| 127 | } |
| 128 | |
| 129 | private void run(VMDetailView view) throws Exception { |
| 130 | try { |
| 131 | // System.out 设为Buffered,需要使用System.out.flush刷新 |
| 132 | System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)), false)); |
| 133 | |
| 134 | int iterations = 0; |
| 135 | while (!view.shouldExit()) { |
| 136 | waitForInput(); |
| 137 | view.printView(); |
| 138 | if (view.shouldExit()) { |
| 139 | break; |
| 140 | } |
| 141 | |
| 142 | System.out.flush(); |
| 143 | |
| 144 | if (maxIterations > 0 && iterations >= maxIterations) { |
| 145 | break; |
| 146 | } |
| 147 | |
| 148 | // 第一次最多只等待3秒 |
| 149 | int sleepSeconds = (iterations == 0) ? Math.min(3, interval) : interval; |
| 150 | |
| 151 | iterations++; |
| 152 | sleepStartTime = System.currentTimeMillis(); |
| 153 | Utils.sleep(sleepSeconds * 1000L); |
| 154 | } |
| 155 | System.out.println(""); |
| 156 | System.out.flush(); |
| 157 | } catch (NoClassDefFoundError e) { |
| 158 | e.printStackTrace(System.out); |
| 159 | System.out.println(Formats.red("ERROR: Some JDK classes cannot be found.")); |
| 160 | System.out.println(" Please check if the JAVA_HOME environment variable has been set to a JDK path."); |
| 161 | System.out.println(""); |
| 162 | System.out.flush(); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | public static void printHelper(OptionParser parser) { |
| 167 | try { |
no test coverage detected