Home arrow static arrow Java Programming [Archive] - Multithread with diffrent parameter
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Multithread with diffrent parameter
This topic has 1 reply on 1 page.

Posts:37
Registered: 7/31/04
Multithread with diffrent parameter  
Jul 31, 2004 9:04 AM



 
i want ask how i can create multi thread with diffrent parmeter??
when i dequeu aparmeter from Queue i want to pass it to new creation thread ..in another word how i can create many thread durig run time ...
i dont know how much parmeter will put in the queue ..put when i dequeue data from queue i want to pass it to the new thread
 

Posts:37,103
Registered: 3/30/99
Re: Multithread with diffrent parameter  
Jul 31, 2004 9:24 AM (reply 1 of 1)



 
Huh?

It's not clear what you're asking.

What do you mean "multi thread with different parameter"?

What do you mean by "dequeuing a parameter from the queue"?

Are you saying that each item that you dequeue should get its own thread? This is not necessarily a good idea. If you have 10,000 items in your queue, do you really want 10,000 threads running? 100,000? 1,000,000?

If this is what you're asking, and assuming the number of items in the queue is small enough to keep this reasonabe, here's basically how you'd do it.
while (queue.isNotEmpty()) {    // Worker is a class that you create that implements Runnable and processes one queue item in its run() method    Worker w = new Worker(queue.next());     Thread th = new Thread(w);    th.start();} 

However, a better way to do it would be to pick some fixed number of threads to process the queue. 5, 10, 100, whatever works for your situation. Your Runnable's run() method then just loops continuously, pulling an item of the queue, proccessing it, and repeating this forever or until you set a "done" flag.
 
This topic has 1 reply on 1 page.