MCPcopy
hub / github.com/vipshop/vjtools / triggerGc

Method triggerGc

vjmap/src/main/java/com/vip/vjtools/vjmap/VJMap.java:243–271  ·  view source on GitHub ↗

Trigger a remote gc using HotSpotVirtualMachine, inspired by jcmd's source code. @param pid

(Integer pid)

Source from the content-addressed store, hash-verified

241 * @param pid
242 */
243 private static void triggerGc(Integer pid) {
244 VirtualMachine vm = null;
245 try {
246 vm = VirtualMachine.attach(String.valueOf(pid));
247 HotSpotVirtualMachine hvm = (HotSpotVirtualMachine) vm;
248 try (InputStream in = hvm.executeJCmd("GC.run");) {
249 byte b[] = new byte[256];
250 int n;
251 do {
252 n = in.read(b);
253 if (n > 0) {
254 String s = new String(b, 0, n, "UTF-8");
255 tty.print(s);
256 }
257 } while (n > 0);
258 tty.println();
259 }
260 } catch (Exception e) {
261 tty.println(e.getMessage());
262 } finally {
263 if (vm != null) {
264 try {
265 vm.detach();
266 } catch (IOException e) {
267 tty.println(e.getMessage());
268 }
269 }
270 }
271 }
272
273 private static void printHelp() {
274 int leftLength = "-all:minsize=1024,byname".length();

Callers 1

mainMethod · 0.95

Calls 2

readMethod · 0.80
getMessageMethod · 0.45

Tested by

no test coverage detected