test/jdk/jdk/jfr/api/consumer/recordingstream/EventProducer.java
author mgronlun
Tue, 29 Oct 2019 15:16:45 +0100
branchJEP-349-branch
changeset 58841 12b4063e357f
parent 58577 7e0f81f63890
permissions -rw-r--r--
license header and newlines
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58841
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
     1
/*
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
     4
 *
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    10
 *
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    15
 * accompanied this code).
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    16
 *
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    20
 *
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    23
 * questions.
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    24
 */
58569
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    25
package jdk.jfr.api.consumer.recordingstream;
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    26
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    27
import jdk.jfr.api.consumer.recordingstream.TestStart.StartEvent;
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    28
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    29
class EventProducer extends Thread {
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    30
    private final Object lock = new Object();
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    31
    private boolean killed = false;
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    32
    public void run() {
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    33
        while (true) {
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    34
            StartEvent s = new StartEvent();
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    35
            s.commit();
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    36
            synchronized (lock) {
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    37
                try {
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    38
                    lock.wait(10);
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    39
                    if (killed) {
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    40
                        return; // end thread
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    41
                    }
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    42
                } catch (InterruptedException e) {
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    43
                    // ignore
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    44
                }
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    45
            }
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    46
        }
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    47
    }
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    48
    public void kill()  {
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    49
        synchronized (lock) {
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    50
            this.killed = true;
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    51
            lock.notifyAll();
58841
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    52
        }
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    53
        try {
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    54
            join();
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    55
        } catch (InterruptedException e) {
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    56
        }
58569
5469bde803fe Extract EventProducer and update TestRecursive
egahlin
parents:
diff changeset
    57
    }
58841
12b4063e357f license header and newlines
mgronlun
parents: 58577
diff changeset
    58
}