Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Aug 2003 11:08:52 +0200
From:      Sheldon Hearn <sheldonh@starjuice.net>
To:        freebsd-java@FreeBSD.org
Subject:   Re: FreeBSD vs Windows 2000 "Advanced" Server
Message-ID:  <20030828090852.GC83970@starjuice.net>
In-Reply-To: <20030828090512.GB83970@starjuice.net>
References:  <20030828090512.GB83970@starjuice.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On (2003/08/28 11:05), Sheldon Hearn wrote:

> The test class at the bottom of this message can fire about 1,800 [1]
> threads on my FreeBSD 5.1-CURRENT box, with the native jdk-1.4.1.  My
> box is a PIII with 1G of RAM.

Oops, make that about 8,000 threads. :-)

And I forgot to include the class source.

Ciao,
Sheldon.


public class TestThreads extends Thread
{
    private long sleepMillis;

    public TestThreads(long sleepMillis)
    {

        this.sleepMillis = sleepMillis;
    }

    public void run()
    {

        try {
            Thread.sleep(sleepMillis);
        } catch (InterruptedException e) {
        }
    }

    public static void main(String[] args)
    {
        int threadCount = 0;
        long sleepMillis = 0;

        try {
            threadCount = new Integer(args[0]).intValue();
            sleepMillis = new Long(args[1]).longValue();
        } catch (Exception e) {
            usage();
        }

        int i = 0;
        try {
            for (i = 0; i < threadCount; i++) {
                TestThreads test = new TestThreads(sleepMillis);
                test.start();
            }
            System.out.println( "TestThreads: successfully fired " +
                threadCount + " threads" );
        } catch (OutOfMemoryError e) {
            System.out.println("TestThreads: after creating " +
                i + " threads: " + e.getMessage());
        }

        try {
            Thread.sleep(sleepMillis);
            System.out.println("TestThreads: waited " + sleepMillis +
                " milliseconds for all threads to complete");
        } catch (InterruptedException e) {
        }
    }

    private static void usage()
    {

        System.err.println("usage: TestThreads threadCount sleepMillis");
        System.exit(1);
    }
}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030828090852.GC83970>