Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: thread pool question

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default thread pool question

    Hello guys. I want to make a distributed system implementation(it's a task for my university). i was wondering if it would be a better idea to use a thread pool to serve clients instead of creating a new thread for each new request .
    I google it and i find that there are advantages and disadvantages. My main idea for the project is to increase scalability and decrease the resources that the system use, so i believe that using a thread pool is a good idea. What's your opinion?

    Thanks in advance.
    Last edited by balexios; October 23rd, 2010 at 03:10 AM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: thread pool question

    I'd say the advantages of a thread pool in this situation outweigh any of the disadvantages. Just my .02

  3. The Following User Says Thank You to copeg For This Useful Post:

    balexios (October 24th, 2010)

  4. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: thread pool question

    There are only a few cases I can think of where only creating new threads is used instead of thread pooling:

    1. You have a tasks which run continuously (for example a GUI) at the same time as discrete tasks (processing a single request). These two items should be run on different threads so your continuous tasks don't become unresponsive. In this case it's much better to create single threads for the tasks you want to run continuously, then create a thread pool to handle the discrete tasks.

    2. You're lazy and don't want to write a task scheduler. Seriously though, it's not to hard to create a simple queue (or heap/priority queue if certain tasks require higher priority) and have a synchronized thread enqueue and distribute tasks.

    3. You have no idea what a thread pool is. Obviously this is not the case.

  5. The Following User Says Thank You to helloworld922 For This Useful Post:

    balexios (October 24th, 2010)

  6. #4
    Junior Member
    Join Date
    Apr 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: thread pool question

    Thanks for the help.

Similar Threads

  1. Thread to EDT
    By Asido in forum Threads
    Replies: 3
    Last Post: October 15th, 2010, 01:13 PM
  2. Thread runs only once and not again
    By enflation in forum Threads
    Replies: 3
    Last Post: June 9th, 2010, 10:51 AM
  3. Thread Sleep, Timer, Button Question
    By tabutcher in forum Java Theory & Questions
    Replies: 1
    Last Post: May 1st, 2010, 02:54 AM
  4. Thread and connection
    By Param in forum Threads
    Replies: 0
    Last Post: April 26th, 2010, 03:43 AM
  5. thread sorting
    By thanos_ in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 12th, 2010, 06:23 PM