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

Thread: Problem with threads

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    4
    My Mood
    Dead
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Problem with threads

    Dear All;

    I write this piece of code to force one of my tasks to work in parallel. The loop at least iterate 5500 times. After afew iteration the system overloaded and stop responding due to Garbage Collection tasks. Please tell me what is wrong and how I can improve the code.

    Since, the code is to long I try to simplify the problem. I create a ExecutorService and a Fixed pool equal to
    "numberOfCPUsAvailable" in a loop in order to lunch "numberOfCPUsAvailable" threads in each iteration. The loop
    iterate at least 5500 times. In each runable I compare a member of and object array with the rest from beginning to that object. After few iterations the system not responding. I increase the heap size in order to prevent GC to start repeatedly and useMarkSweepGC but it is not effective.

    for (int i = 5500; i >= 0 ; i--)
    {
           	distanceExecutor = Executors.newFixedThreadPool(numOfAvailableCPUs);
     
        	 AntibodyDistanceChecker[] DCT = new AntibodyDistanceChecker[numOfAvailableCPUs];
     
        	 int step = (int) Math.floor(totalUnique / numOfAvailableCPUs );
     
        	 for(int t = 0; t < numOfAvailableCPUs; t++)
        	 {
    	    DCT[t] = new AntibodyDistanceChecker("DCT"+t+i, minAllowedDistance);
              }
     
              for(int e = 0; e < numOfAvailableCPUs; e++)
            	  distanceExecutor.execute(DCT[e]);
     
        	 distanceExecutor.shutdown();
    	 while (!distanceExecutor.isTerminated()) {}
     
    	distanceExecutor = null;
    	DCT = null;
    	        }
    Last edited by Shahram; October 14th, 2011 at 02:21 AM. Reason: Change in code


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Problem with threads

    If you want help, you'll have to provide an SSCCE that demonstrates the problem. We can't do much by looking at incomplete (or overly lengthy) code.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    4
    My Mood
    Dead
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Problem with threads

    Lets simplify the problem. I create 5 threads inside a loop which runs 500 times. Each time I create a ExecutorService and a fixedpool of 5. After few iterations the system overloaded and stop responding. What should I do?

  4. #4
    Junior Member
    Join Date
    Sep 2011
    Posts
    4
    My Mood
    Dead
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Problem with threads

    I made the code simpler. I hope this will help. Inside runable I compare a member of an arrays of object with the rest of the array from beginning up to that point.

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Problem with threads

    Please post in the correct forum. Thread moved to - Threads
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Problem with threads
    By Spidey1980 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 20th, 2011, 09:04 AM
  2. threads
    By crazed8s in forum Threads
    Replies: 2
    Last Post: December 14th, 2010, 05:33 AM
  3. Working with threads
    By tccool in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 12th, 2010, 10:21 AM
  4. Problem with designing threads & abstraction
    By gilme in forum What's Wrong With My Code?
    Replies: 6
    Last Post: June 14th, 2010, 06:48 AM
  5. threads in gui
    By urosz in forum AWT / Java Swing
    Replies: 1
    Last Post: November 3rd, 2009, 05:20 PM