This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to handle excess number of thread despite of limited efficiency of the machine  RSS feed

 
shashi anand
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I got this question in an interview.And I was not sure how to respond this type of question. Kindly provide some heads-up regarding this. The question is "You have 1000 jobs to be done. Your machine capable of handling 50 threads at a time. Write a program in java that can run only 50 thread at a time and when some jobs get done start another."
Thanks
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

What was your answer? The obvious solution would be to create a thread pool with 50 threads, and have each thread work on 20 jobs successively (assuming that jobs are of equal workload and importance). Or you can have queue of jobs ordered by priority, and assign from the top of the queue as worker threads become available. A java.util.concurrent.ExecutorService and its related classes in java.util.concurrent would greatly help with that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!