当前位置: 首页>>代码示例>>Java>>正文


Java ProcessTools.getProcessId方法代码示例

本文整理汇总了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();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:29,代码来源:TestApplication.java

示例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();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:Application.java

示例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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:DumpHeap.java

示例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);
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:76,代码来源:JpsBase.java


注:本文中的jdk.testlibrary.ProcessTools.getProcessId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。