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

Thread: Java Concurrent Programming

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

    Default Java Concurrent Programming

    Hello Members,
    I am kind of new to java programming (started working in java last 3-4 months)... I am working on an applicaiton which handles lot of transactions on a daily basis...I tried useing threadpool for handling concurrent requests by using the Linked Blocking Queue. The thread pool always will have 50-100 threads running in the background and these will share the work. What happens here is that I am not seering the real concurrency here due to some reasons...Each thread will pick the message from this LBQueue and open a seperate commandline process to run some command and give the output back as std out or as a file which will then be put into the queue. Servlet then will pick the response from the queue and returns to the caller. Right now, I am getting the only 2-3 transactions per second but I want to achieve atleast 10-15 TPS rate..I tried to increase the thread pool size from 25 to 50, 100, 200 but not seeing any CPU hike rather than its taking longer processing time. Can anybody help me how I can achive better TPS with concurrent programming in java...

    Any help would be greately appreciated.. Thanks in advance....

    Sudhakar


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

    Default Re: Java Concurrent Programming

    Processors can only process information at a certain max rate, no matter how many threads you spawn the processor will max out at some point. Within reason increasing the number of threads helps deal with several tasks at once, but increasing too much and you will start developing overhead from having to manage all those threads - probably the reason you see a longer processing time with increased threads. Optimize your code whichever way you can so each thread needs less processor time, and stick with fewer rather than more threads.

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

    Default Re: Java Concurrent Programming

    A good rule of thumb is try to stick to the same number of threads as you have processor cores, give or take one or two for user interactions/GUI if any.

  4. #4
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Java Concurrent Programming

    A good thing to do as well is to go over the code that is run on each thread execution, try to cut down on unnecessary calls to new etc. Optimise the code so it will run faster.

    // Json

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

    Default Re: Java Concurrent Programming

    Thanks a lot everybody for your responses... I did try some code optimizations and will take a look at one more time...Meanwhile, do you suggest a number for the thread pool size that I can limit ...

    Thanks..
    Sudhakar

  6. #6
    Junior Member
    Join Date
    May 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Concurrent Programming

    Is integrating the commandline process into the main Java application an option? I think that's where you bottle neck lies.

    Creating new processes is an expensive task when it comes to OS resources. If you managed to integrate all the processes into one you will certainly see a dramatic improvement in the TPS rate.

  7. #7
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Java Concurrent Programming

    Quote Originally Posted by vzwsudha View Post
    I did try some code optimizations and will take a look at one more time...
    Are you using a profiler to find the bottlenecks? There's usually little benefit from trying to optimize code unless you know exactly what is slowing things down.

    If you use a performance profiler to find the methods at fault, you can target your optimization effort.

Similar Threads

  1. Is Java Programming Best?
    By messenger in forum Java IDEs
    Replies: 3
    Last Post: May 4th, 2010, 09:11 PM
  2. Please help me with this Java programming
    By simply_stunning79 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 12th, 2010, 08:04 AM
  3. Please help me with this Java programming
    By simply_stunning79 in forum Algorithms & Recursion
    Replies: 1
    Last Post: February 22nd, 2010, 07:48 PM
  4. Towards java programming...
    By emigrant in forum Member Introductions
    Replies: 1
    Last Post: February 15th, 2010, 03:17 AM
  5. Please help me with this Java programming
    By simply_stunning79 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 14th, 2010, 06:42 AM