Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Multithreading CPU Usage and Performance

 
R Thangaraj
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Requirement : Sort the Text file with list of names and calculate score based on some business logic for each name and get the aggregated score.

My Approach : 1. External sort the Text file ( Large text file)
2. Read line by line and Put it in the BlockingQueue
3. Read by multiple threads and calculate the score concurrently

Issue : Program is working fine with Single Thread. If i changed the number of threads to multiple, My CPU Usage 100%, it is hanging. No Response.
I am using ExecutorService to run the thread.

Any help would be appreciated.

Thanks
 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Issue : Program is working fine with Single Thread. If i changed the number of threads to multiple, My CPU Usage 100%, it is hanging. No Response.
I am using ExecutorService to run the thread.


How many threads you are creating at a time ?
Are you using Executor Service and Java's Thread pooling mechanism for this ?

If not can you try to implement the Thread Pool and come up with your update

Thanks ,
Satya


 
R Thangaraj
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

I found the issue, only one thread is getting the END of the queue indicator, other threads are waiting for the END indicator and running indefinitely.

When a Thread received the END of the indicator, i am enqueue the END object again in to the Queue, so that other threads stop the execution.

 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like you're putting a special token into the queue to signal that it's the end of the queue. You're using a BlockingQueue, which is a good start. However I'd suggest using some kind of ThreadPoolExecutor as well; if you did that then the Executor would take care of distributing tasks to threads for processing, and you would just have to call its shutdown() method when you reached the end of the input and had no more work to give it.

When you read the API documentation for ThreadPoolExecutor you may find it very daunting at first, since it goes through a long list of features and possibilities. However I would suggest just using the simplest version of ThreadPoolExecutor, since that's likely all you are going to need.
 
Forget Steve. Look at this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!