Maximum number of threads - error

Discussion in 'Java' started by mark, Nov 22, 2006.

  1. mark

    mark Guest

    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
     
    mark, Nov 22, 2006
    #1
    1. Advertising

  2. mark

    M.J. Dance Guest

    mark wrote:
    > 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
     
    M.J. Dance, Nov 22, 2006
    #2
    1. Advertising

  3. mark

    Daniel Pitts Guest

    mark wrote:
    > 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.
     
    Daniel Pitts, Nov 22, 2006
    #3
  4. mark

    mark Guest

    Hello,

    > 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.


    Thank you Daniel - that was the thing I was looking for (even if it
    still needs 1.5 :)).

    Regards, mark
     
    mark, Nov 23, 2006
    #4
  5. mark

    Daniel Pitts Guest

    mark wrote:
    > Hello,
    >
    > > 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.

    >
    > Thank you Daniel - that was the thing I was looking for (even if it
    > still needs 1.5 :)).
    >
    > Regards, mark


    You're welcome.
     
    Daniel Pitts, Nov 24, 2006
    #5
  6. mark

    Lew Guest

    Daniel Pitts wrote:
    > 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.


    mark wrote:
    > 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
     
    Lew, Nov 27, 2006
    #6
  7. mark

    Daniel Pitts Guest

    Lew wrote:
    > Daniel Pitts wrote:
    > > 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.

    >
    > mark wrote:
    > > 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


    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.
     
    Daniel Pitts, Nov 27, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mayur
    Replies:
    2
    Views:
    1,033
    Natty Gur
    Jul 2, 2004
  2. Kirby Angell

    Maximum number of threads

    Kirby Angell, Sep 29, 2004, in forum: Python
    Replies:
    7
    Views:
    516
    Kirby Angell
    Oct 4, 2004
  3. Paul Sijben

    maximum number of threads

    Paul Sijben, Jan 10, 2007, in forum: Python
    Replies:
    12
    Views:
    843
    Ganesan Rajagopal
    Jan 12, 2007
  4. hg
    Replies:
    4
    Views:
    645
    Jeremy Sanders
    Jan 10, 2007
  5. phanhuyich
    Replies:
    4
    Views:
    294
Loading...

Share This Page