Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to wait in main method until all thread are finished  RSS feed

 
Md Uddin
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am very new with thread. Here is my problem.

I have one JSP where myApp.main method called (something like below):


Separate threads creates from after we call test.start(); .Right now the main method return where it was called from (my JSP), before all the thread finished (created from test.start())
That means it calls test.start() and return (doesn't wait all the threads to finish).

What I need to do to wait after test.start() method without returning from the main method till all the thread finish. So that when my JSP execute the line anotherObject.doSomething(); all the threads are finished.




Scenario:
---------------------------------------------------------------
myApp.main()
myApp.start()
ABC.readData()
JaxbReader.addDataEventListener(ABC)
JaxbReader.startRead()
Creates new JaxbReader.ThreadReader (extends Thread)
JaxbReader.ThreadReader.start() -> Runs JaxbReader.ThreadReader in a thread
<< myApp.main() thread ends >>

<< Separate Thread >>
JaxbReader.run()
... It creates More threads

<< Separate Thread >>
...
...
---------------------------------------------------------------------

Thank you in advance.
[ November 07, 2008: Message edited by: Md Uddin ]
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at different flavors of join method and Java concurrency tutorial
 
Md Uddin
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Nitesh for your reply.

But using join() seems not working. I already tried before posting here.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

But using join() seems not working.

Please post the code where you use join.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!