Click here to Skip to main content
15,908,673 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 3 threads connecting to server..
how will i know if 1st thread is done?
so that i can start 2nd thread.
Posted

1 solution

You create some sort of syncRoot object, pass it to both thread 1 and thread 2. Thread 2 waits on the syncRoot (syncRoot.wait()), when thread 1 is done, it notifies on the syncRoot (syncRoot.notify()).

What's more interesting is why you want this, if the logic of thread 2 is always running at the end of thread 1, then it's better to not have them on separate threads but just use one thread instead. The whole point of threads in that they run in parallel, not in sequence.

Yes, there is a need to sometimes synchronize execution between threads but if the plan is to first run thread 1 to completion and then run thread 2 to completion then I think you're misusing your threads.

/Fredrik
 
Share this answer
 
Comments
dinahgee1419 8-Aug-13 3:36am    
hmmm.. actually the application does not have 2 threads only.. there are a lot of threads that will call a main thread. now the issue is, once a thread calls the main thread, it should wait for reply from main thread that it is finish processing the call before another thread can call the main thread..
dinahgee1419 8-Aug-13 3:36am    
can u suggest how will i do it? that a main thread will response that it is finish processing

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900