for (int i = 0; i < contenders.length; i++) { contenders[i].exit(); }
Competitor.exit();
    public void testFairness() {        String url = m_prefix + "fairness";        int size = 10;        ConnectionSource src = new PooledConnectionSource(url, size, 5000);        // These threads will compete for the resources in the        // connection pool in an environment with high thread        // contention.        Competitor[] competitors = new Competitor[10];        for (int i = 0; i < competitors.length; i++) {            competitors[i] = new Competitor(src, 30000);        }        // These threads will create a highly contentious enviornment        // for the competing threads. We want significantly more of        // these threads than there are competing threads so that the        // overall contention remains relatively constant during the        // time in which the competing threads are only partially        // started or exited.        Competitor[] contenders = new Competitor[10*competitors.length];        for (int i = 0; i < contenders.length; i++) {            Competitor c = new Competitor(src);            c.setDaemon(true);            c.start();            contenders[i] = c;        }        // Start the competing threads.        for (int i = 0; i < competitors.length; i++) {            competitors[i].start();        }        // Wait for the competing threads.        try {            for (int i = 0; i < competitors.length; i++) {                competitors[i].join();            }        } catch (InterruptedException e) {            throw new UncheckedWrapperException(e);        }        // Turn off the contention.        for (int i = 0; i < contenders.length; i++) {            contenders[i].exit();        }        // Check that we did not exceed the connection pool size limit.        assertEquals            ("incorrect connection count", size, getConnections(url).size());        // Compute our fairness metric and assert that it is within a        // tolerable range.        int min = competitors[0].getCount();        int max = 0;        int sum = 0;        for (int i = 0; i < competitors.length; i++) {            int count = competitors[i].getCount();            if (count < min) { min = count; }            if (count > max) { max = count; }            sum += count;        }        double avg = ((double)sum)/competitors.length;        double minscaled = min/avg;        double maxscaled = max/avg;        assertTrue            ("unfair pooling results:" +             "\n  min = " + min +             "\n  max = " + max +             "\n  avg = " + avg +             "\n  minscaled = " + minscaled +             "\n  maxscaled = " + maxscaled,             (minscaled > 0.1) && (maxscaled < 10));    }