RFR: 8265153: add time based test for ThreadMXBean.getThreadInfo() and ThreadInfo.getLockOwnerName() [v5]

Chris Plummer cjplummer at openjdk.java.net
Fri May 14 22:57:39 UTC 2021


On Fri, 14 May 2021 22:04:05 GMT, Daniel D. Daugherty <dcubed at openjdk.org> wrote:

>> test/hotspot/jtreg/serviceability/monitoring/ThreadInfo/getLockOwnerName/getLockOwnerName.java line 329:
>> 
>>> 327:         // - releases threadLock
>>> 328:         //
>>> 329:         if (getName().equals("blocker")) {
>> 
>> Bit of a nit here, but is there a reason not to just create separate Thread subclasses for each of the 3 types of threads you are handling here? Or just make these each separate static methods of the main class and use the instantiate the Thread class with a lambda.
>
> This new test is a variation of a 20 year old test that I recently ported to JVM/TI
> and integrated. 20 years ago, it was much simpler to write the test this way.
> I could create a separate Thread subclass for each "role", but I'd rather not
> do that since it will no longer be easy to compare this test to its siblings.
> 
> As for lambdas, I know absolutely zero about writing lambda code.

Ok. I get it about lambdas, but they can be useful for simplifying thread tasks without creating a subclass. Here are a few examples, but no need for you to replicate any them:


    // create thread with specified method as the "run" method
    Thread t = new Thread(this::testMethod);
    t.start();



    // create thread with the specified code block as the "run" method
    Thread t1 = new Thread(() -> {
        synchronized (lock1) {
            System.out.println("Thread in sync section 1: "
                    + Thread.currentThread().getName());
            test1();
        }



    // create a static Runnable object using a lambda and use it as the Runnable for a new Thread
    static final Runnable CONSUMER = () -> {
        remove(QUEUE);
    };
    ...
    Thread t = new Thread(CONSUMER);

-------------

PR: https://git.openjdk.java.net/jdk/pull/3478


More information about the hotspot-runtime-dev mailing list