public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
From: "efly at javaresearch dot org" <gcc-bugzilla@gcc.gnu.org>
To: java-prs@gcc.gnu.org
Subject: [Bug java/16342] New: too many threads error
Date: Sat, 03 Jul 2004 04:06:00 -0000	[thread overview]
Message-ID: <20040703040557.16342.efly@javaresearch.org> (raw)

Has anybody encountered this problem? When I test java thread using thisiscool
gcj3.4, "too many threads" error thrown.

Sample source code:

class Account {
	String name;

	float amount;

	public Account(String name, float amount) {
		this.name = name;
		this.amount = amount;
	}

	public void deposit(float amt) {
		float tmp = amount;
		tmp += amt;

		try {
			Thread.sleep(100);
		} catch (InterruptedException e) {
			// ignore
		}

		amount = tmp;
	}

	public void withdraw(float amt) {
		float tmp = amount;
		tmp -= amt;

		try {
			Thread.sleep(100);
		} catch (InterruptedException e) {
			// ignore
		}

		amount = tmp;
	}

	public float getBalance() {
		return amount;
	}
}

public class AccountTest {
	private static int NUM_OF_THREAD = 1000;

	static Thread[] threads = new Thread[NUM_OF_THREAD];

	public static void main(String[] args) {
		System.out.println("start...");
		long start = System.currentTimeMillis();
		final Account acc = new Account("John", 1000.0f);
		for (int i = 0; i < NUM_OF_THREAD; i++) {
			threads[i] = new Thread(new Runnable() {
				public void run() {
					acc.deposit(100.0f);
					acc.withdraw(100.0f);
				}
			});
			threads[i].start();
		}

		for (int i = 0; i < NUM_OF_THREAD; i++) {
			try {
				threads[i].join(); 
			} catch (InterruptedException e) {
				// ignore
			}
		}
		long end = System.currentTimeMillis();
		System.out.println("Finally, John's balance is:" + acc.getBalance()
				+ " time used:" + (end - start) + "ms");
	}

}

J Zhou 
efly@javaresearch.org

-- 
           Summary: too many threads error
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: java
        AssignedTo: membar at gcc dot gnu dot org
        ReportedBy: efly at javaresearch dot org
                CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu
                    dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16342


             reply	other threads:[~2004-07-03  4:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-03  4:06 efly at javaresearch dot org [this message]
2004-07-03 18:45 ` [Bug java/16342] [win32] " pinskia at gcc dot gnu dot org
2004-07-03 22:59 ` [Bug libgcj/16342] " pinskia at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040703040557.16342.efly@javaresearch.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=java-prs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).