Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript 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: 42972
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!