本文整理汇总了Java中jdk.testlibrary.ProcessTools.getProcessId方法的典型用法代码示例。如果您正苦于以下问题:Java ProcessTools.getProcessId方法的具体用法?Java ProcessTools.getProcessId怎么用?Java ProcessTools.getProcessId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.testlibrary.ProcessTools
的用法示例。
在下文中一共展示了ProcessTools.getProcessId方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
// Some tests require the application to exit immediately
if (args.length > 0 && args[0].equals("-exit")) {
return;
}
// bind to a random port
ServerSocket ss = new ServerSocket(0);
int port = ss.getLocalPort();
int pid = -1;
try {
pid = ProcessTools.getProcessId();
} catch (Exception e) {
e.printStackTrace();
}
// signal test that we are started - do not remove these lines!!
System.out.println("port:" + port);
System.out.println("pid:" + pid);
System.out.println("waiting for the manager ...");
System.out.flush();
// wait for manager to connect
Socket s = ss.accept();
s.close();
ss.close();
}
示例2: main
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
// bind to a random port
if (args.length < 1) {
System.err.println("First argument should be path to output file.");
}
String outFileName = args[0];
ServerSocket ss = new ServerSocket(0);
int port = ss.getLocalPort();
int pid = ProcessTools.getProcessId();
System.out.println("shutdownPort=" + port);
System.out.println("pid=" + pid);
System.out.flush();
try (PrintWriter writer = new PrintWriter(outFileName)) {
writer.println("shutdownPort=" + port);
writer.println("pid=" + pid);
writer.println("done");
writer.flush();
}
// wait for test harness to connect
Socket s = ss.accept();
s.close();
ss.close();
}
示例3: main
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
List<HotSpotDiagnosticMXBean> list = ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
File dump = new File(ProcessTools.getProcessId() + ".hprof");
if (dump.exists()) {
dump.delete();
}
System.out.println("Dumping to file: " + dump.getAbsolutePath());
list.get(0).dumpHeap(dump.getAbsolutePath(), true);
verifyDumpFile(dump);
dump.delete();
}
示例4: main
import jdk.testlibrary.ProcessTools; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
int pid = ProcessTools.getProcessId();
List<List<JpsHelper.JpsArg>> combinations = JpsHelper.JpsArg.generateCombinations();
for (List<JpsHelper.JpsArg> combination : combinations) {
OutputAnalyzer output = JpsHelper.jps(JpsHelper.JpsArg.asCmdArray(combination));
output.shouldHaveExitValue(0);
boolean isQuiet = false;
boolean isFull = false;
String pattern;
for (JpsHelper.JpsArg jpsArg : combination) {
switch (jpsArg) {
case q:
// If '-q' is specified output should contain only a list of local VM identifiers:
// 30673
isQuiet = true;
JpsHelper.verifyJpsOutput(output, "^\\d+$");
output.shouldContain(Integer.toString(pid));
break;
case l:
// If '-l' is specified output should contain the full package name for the application's main class
// or the full path name to the application's JAR file:
// 30673 /tmp/jtreg/jtreg-workdir/scratch/JpsBase.jar ...
isFull = true;
pattern = "^" + pid + "\\s+" + replaceSpecialChars(fullProcessName) + ".*";
output.shouldMatch(pattern);
break;
case m:
// If '-m' is specified output should contain the arguments passed to the main method:
// 30673 JpsBase monkey ...
for (String arg : args) {
pattern = "^" + pid + ".*" + replaceSpecialChars(arg) + ".*";
output.shouldMatch(pattern);
}
break;
case v:
// If '-v' is specified output should contain VM arguments:
// 30673 JpsBase -Xmx512m -XX:+UseParallelGC -XX:Flags=/tmp/jtreg/jtreg-workdir/scratch/vmflags ...
for (String vmArg : JpsHelper.getVmArgs()) {
pattern = "^" + pid + ".*" + replaceSpecialChars(vmArg) + ".*";
output.shouldMatch(pattern);
}
break;
case V:
// If '-V' is specified output should contain VM flags:
// 30673 JpsBase +DisableExplicitGC ...
pattern = "^" + pid + ".*" + replaceSpecialChars(JpsHelper.VM_FLAG) + ".*";
output.shouldMatch(pattern);
break;
}
if (isQuiet) {
break;
}
}
if (!isQuiet) {
// Verify output line by line.
// Output should only contain lines with pids after the first line with pid.
JpsHelper.verifyJpsOutput(output, "^\\d+\\s+.*");
if (!isFull) {
pattern = "^" + pid + "\\s+" + replaceSpecialChars(shortProcessName);
if (combination.isEmpty()) {
// If no arguments are specified output should only contain
// pid and process name
pattern += "$";
} else {
pattern += ".*";
}
output.shouldMatch(pattern);
}
}
}
}