jdk/test/javax/management/monitor/MultiMonitorTest.java
author rprotacio
Wed, 02 Mar 2016 15:10:38 -0500
changeset 36396 26a241a959de
parent 30376 2ccf2cf7ea48
child 44100 a5803b63fc79
permissions -rw-r--r--
8145098: JNI GetVersion should return JNI_VERSION_9 Summary: Updated JNI_VERSION for current version to be JNI_VERSION_9 Reviewed-by: hseigel, gtriantafill, dholmes, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 30046
diff changeset
     2
 * Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4984057
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test that monitors can sample a large number of attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Eamonn McManus
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 30046
diff changeset
    29
 * @modules java.management
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run clean MultiMonitorTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run build MultiMonitorTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run main MultiMonitorTest
30046
cf2c86e1819e 8078334: Mark regression tests using randomness
darcy
parents: 5506
diff changeset
    33
 * @key randomness
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.management.monitor.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/* We create N MBeans and three monitors, one for each different
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
   monitor type.  Each monitor monitors a single attribute in each of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
   the N MBeans.  We arrange for the trigger condition to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
   satisfied, so the listener we register on each monitor should get N
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
   notifications.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class MultiMonitorTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static final int N = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    static final ObjectName[] mbeanNames = new ObjectName[N];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    static final Monitored[] monitored = new Monitored[N];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    static final int COUNTER_THRESHOLD = 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    static final int OVER_COUNTER_THRESHOLD = 2000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    static final double GAUGE_THRESHOLD = 1000.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    static final double OVER_GAUGE_THRESHOLD = 2000.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static final String STRING_TO_COMPARE = "chou";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    static final String DIFFERENT_STRING = "chevre";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        System.out.println("Test that monitors can sample a large " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                           "number of attributes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        final MBeanServer mbs = MBeanServerFactory.createMBeanServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        for (int i = 0; i < N; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            mbeanNames[i] = new ObjectName(":type=Monitored,instance=" + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            monitored[i] = new Monitored();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            mbs.registerMBean(monitored[i], mbeanNames[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        final ObjectName counterMonitor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            new ObjectName(":type=CounterMonitor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        final ObjectName gaugeMonitor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            new ObjectName(":type=GaugeMonitor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        final ObjectName stringMonitor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            new ObjectName(":type=StringMonitor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        final ObjectName[] monitorNames =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            new ObjectName[] {counterMonitor, gaugeMonitor, stringMonitor};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        final String[] attrNames =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            new String[] {"CounterValue", "GaugeValue", "StringValue"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        mbs.createMBean(CounterMonitor.class.getName(), counterMonitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        mbs.createMBean(GaugeMonitor.class.getName(), gaugeMonitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        mbs.createMBean(StringMonitor.class.getName(), stringMonitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        final CounterMonitorMBean counterProxy = (CounterMonitorMBean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            MBeanServerInvocationHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            .newProxyInstance(mbs, counterMonitor, CounterMonitorMBean.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                              false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        final GaugeMonitorMBean gaugeProxy = (GaugeMonitorMBean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            MBeanServerInvocationHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            .newProxyInstance(mbs, gaugeMonitor, GaugeMonitorMBean.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                              false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        final StringMonitorMBean stringProxy = (StringMonitorMBean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            MBeanServerInvocationHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            .newProxyInstance(mbs, stringMonitor, StringMonitorMBean.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                              false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        final MonitorMBean[] proxies = new MonitorMBean[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            counterProxy, gaugeProxy, stringProxy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        for (int i = 0; i < 3; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            proxies[i].setGranularityPeriod(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            proxies[i].setObservedAttribute(attrNames[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            for (int j = 0; j < N; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                proxies[i].addObservedObject(mbeanNames[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        final CountListener[] listeners = new CountListener[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            new CountListener(), new CountListener(), new CountListener()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        for (int i = 0; i < 3; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            mbs.addNotificationListener(monitorNames[i], listeners[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                                        null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        counterProxy.setInitThreshold(new Integer(COUNTER_THRESHOLD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        counterProxy.setNotify(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        gaugeProxy.setThresholds(new Double(GAUGE_THRESHOLD), new Double(0.0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        gaugeProxy.setNotifyHigh(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        stringProxy.setStringToCompare(STRING_TO_COMPARE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        stringProxy.setNotifyDiffer(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        // A couple of granularity periods to detect bad behaviour
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        Thread.sleep(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if (!listenersAreAll(0, listeners)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            System.out.println("TEST FAILED: listeners not all 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        for (int i = 0; i < 3; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            proxies[i].start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        long startTime = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        while (!listenersAreAll(N, listeners)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
               && System.currentTimeMillis() < startTime + 5000)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            Thread.sleep(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        // More time for bad behaviour
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        Thread.sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (!listenersAreAll(N, listeners)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            System.out.print("TEST FAILED: listener counts wrong:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            for (int i = 0; i < listeners.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                System.out.print(" " + listeners[i].getCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        for (int i = 0; i < 3; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            proxies[i].stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            for (int j = 0; j < N; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                proxies[i].removeObservedObject(mbeanNames[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            ObjectName[] observed = proxies[i].getObservedObjects();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            if (observed.length != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                System.out.println("TEST FAILED: not all observed objects " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                   "removed: " + Arrays.asList(observed));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        System.out.println("Test passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public static interface MonitoredMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        public int getCounterValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        public double getGaugeValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        public String getStringValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public static class Monitored implements MonitoredMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        /* We give a small random number of normal readings (possibly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
           zero) before giving a reading that provokes a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
           notification.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        private int okCounter = randomInt(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        private int okGauge = randomInt(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        private int okString = randomInt(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        public synchronized int getCounterValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            if (--okCounter >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                return OVER_COUNTER_THRESHOLD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        public synchronized double getGaugeValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            if (--okGauge >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                return 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                return OVER_GAUGE_THRESHOLD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        public synchronized String getStringValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            if (--okString >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                return STRING_TO_COMPARE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                return DIFFERENT_STRING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public static class CountListener implements NotificationListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        private int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        public synchronized void handleNotification(Notification n, Object h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            if (!(n instanceof MonitorNotification)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                System.out.println("TEST FAILED: bad notif: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                                   n.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            if (n.getType().indexOf("error") >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                System.out.println("TEST FAILED: error notif: " + n.getType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        public synchronized int getCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    private static boolean listenersAreAll(int n, CountListener[] listeners) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        for (int i = 0; i < listeners.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            if (listeners[i].getCount() != n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    private static final Random random = new Random();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    static synchronized int randomInt(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        return random.nextInt(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
}