return of thread starting new method
hi,
I have an application that runs a thread pool, each thread builds up a linklist. what I need to know is that I Need to get this linklist only when the thread is done and pass it to another method in another object where all of these linklists are kept.
How do I do this, I dont have a huge knowledge on threads :(
I believe I can add this new objective ( to keep all the linklists ) to be run in the same thread pool as well or should I make a new seperate thread to run it.
Other thing is I believe I can synchronize that method so it waits until one link list is finished, but is this an efficient way I mean the threads in my thread pool changes fast, so is it ok to make the method synchronized. I mean does that decrease the performance, say each thread takes about 1 sec to finish...
Thank you.
[843 byte] By [
AlienXa] at [2007-11-27 9:16:01]

> When you say you want to do something only when the
> thread is done, that's a cue for you to use the
> Thread.join() method.
Possibly. However, if there are multiple threads, and we want something to be executed as soon as each one dies, then we'd probably want to have the last step of each run method to call a particular method to let the controller know that that thread is done.
jverda at 2007-7-12 22:05:35 >

thanks
each thread is for obtaining information from network stream which takes up time. one thread handles one IP. If I use only 1 thread It takes a hell of a long time.. I said 1 sec for 1 thread as just a measure but practically it takes more than that ...
Hope its clear... :)
I'll try the join method, the main thread which starts the thread pool execution waits until everything is done. so is it OK if I run the linklist processing method in the mainthread's stack or shall I use a thread in the thread pool for that..
Cheers
> thanks
>
> each thread is for obtaining information from network
> stream which takes up time. one thread handles one
> IP. If I use only 1 thread It takes a hell of a long
> time.. I said 1 sec for 1 thread as just a measure
> but practically it takes more than that ...
Okay. I just wanted to make sure you had a good reason to use multiple threads, rather than thinking that multithreading a CPU-intensive operation would magically make it go faster.
> I'll try the join method, the main thread which
> starts the thread pool execution waits until
> everything is done.
That can work, depending on your requirements. If you want the main thread to stop and do nothing until ALL the other threads are done, that's fine. But if you want something to happen as soon as each thread finishes, join is not a good way to go.
> so is it OK if I run the linklist
> processing method in the mainthread's stack or shall
> I use a thread in the thread pool for that..
I don't understand enough about what you're trying to do to answer that.
jverda at 2007-7-12 22:05:35 >
