• Post Reply Bookmark Topic Watch Topic
  • New Topic

Waking dynamic threads  RSS feed

 
Naresh Rajan
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an applcication that needs to write into 36 different files. I will get to know the size of the data to be written only during run time. So based on the file sizes i need to wake dynamic threads. I have decided that there will be 3-5 threads, but I done know how!!! please help me in doing things.

Naresh
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look into the thread pooling in Java 5. Some number of threads sit and wait for work to appear in a queue. When a Runnable object appears, one of the threads pulls it off the queue and runs it. Start with the JavaDoc for Executors and Google for examples.

In your case it sounds like the Runnable would process a file in its run() method, and you'd put a Runnable in queue any time you spot a new file.
[ February 20, 2006: Message edited by: Stan James ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!