Maximum number of threads - error

M

mark

Hello,

I have just built an application (J2SE) which creates many threads for
I/O socket operations. Under very specific circumstances (very slow
network connection, many I/O operations) I got an error:

Exception in thread "main" java.lang.OutOfMemoryError: unable to create
new native thread

Therefore I am just wondering is it possible to put all the threads to
some finite queue (which size would be specified by the operating
system) so that it could execute only some of the threads keeping the
rest in the queue (FIFO preferably). All the threads are independent so
there should be no problems with blocking. I just wanted to do so just
to improve my performance and avoid such errors in very specific cases.
Would be very grateful for help.

Best, Markus
 
M

M.J. Dance

mark said:
Hello,

I have just built an application (J2SE) which creates many threads for
I/O socket operations. Under very specific circumstances (very slow
network connection, many I/O operations) I got an error:

Exception in thread "main" java.lang.OutOfMemoryError: unable to create
new native thread

Therefore I am just wondering is it possible to put all the threads to
some finite queue (which size would be specified by the operating
system) so that it could execute only some of the threads keeping the
rest in the queue (FIFO preferably). All the threads are independent so
there should be no problems with blocking. I just wanted to do so just
to improve my performance and avoid such errors in very specific cases.
Would be very grateful for help.

http://www.google.com/search?q=java+threadpool
 
D

Daniel Pitts

mark said:
Hello,

I have just built an application (J2SE) which creates many threads for
I/O socket operations. Under very specific circumstances (very slow
network connection, many I/O operations) I got an error:

Exception in thread "main" java.lang.OutOfMemoryError: unable to create
new native thread

Therefore I am just wondering is it possible to put all the threads to
some finite queue (which size would be specified by the operating
system) so that it could execute only some of the threads keeping the
rest in the queue (FIFO preferably). All the threads are independent so
there should be no problems with blocking. I just wanted to do so just
to improve my performance and avoid such errors in very specific cases.
Would be very grateful for help.

Best, Markus

Look into ThreadPoolExecutor
<http://java.sun.com/j2se/1.5.0/docs/api/index.html?java/util/concurrent/ThreadPoolExecutor.html>

There is a lot of nifty things in the java.util.concurrent package.
Although they require java 1.5.
 
L

Lew

Daniel said:
> Look into ThreadPoolExecutor
>
>
> There is a lot of nifty things in the java.util.concurrent package.
> Although they require java 1.5.
Thank you Daniel - that was the thing I was looking for (even if it
still needs 1.5 :)).

Java 5 has been out for two years now. It's up to revision 9. It's not beta
software any more, folks.

- Lew
 
D

Daniel Pitts

Lew said:
Java 5 has been out for two years now. It's up to revision 9. It's not beta
software any more, folks.

- Lew

That is true, and oh what a wonderful world it would be if every Java
shop had completely ported existing Java 1.4 (or lower) applications to
the latest stable Java. Unfortunately, the real world is often
neglectful of such considerations, as 1.5 is not 100% backward
compatible.

I would start all of my new projects in 1.5, and port any 1.4 project
if I had the choice. Luckily my Job allows me to start new projects in
1.5, but we have legacy systems to support.

Although, it seems Mark is fine using 1.5, which is very much a good
thing.

- Daniel.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top