This is the mail archive of the java-prs@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug java/16342] New: too many threads error


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]