Spawning threads like this is not the way to go. Use an ExecutorService and specify the pool to be 5. Put all the files in something like a BlockingQueue or another thread-safe collection and all the executing ones can just poll() it at will.
Read full article from multithreading - How to make a thread limit in Java - Stack Overflow
No comments:
Post a Comment