File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes How to wait in main method until all thread are finished Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "How to wait in main method until all thread are finished" Watch "How to wait in main method until all thread are finished" New topic
Author

How to wait in main method until all thread are finished

Md Uddin
Greenhorn

Joined: Jan 11, 2006
Posts: 28
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 ]

MURAD (SCJP 5.0, SCWCD 1.4)
If you learn to program in Java, you'll never be without a job! (Patricia Seybold in 1998) - Knowing the syntax of Java does not make someone a software engineer. (John Knight)
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Have a look at different flavors of join method and Java concurrency tutorial


apigee, a better way to API!
Md Uddin
Greenhorn

Joined: Jan 11, 2006
Posts: 28
Thank you Nitesh for your reply.

But using join() seems not working. I already tried before posting here.
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638


But using join() seems not working.

Please post the code where you use join.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel
 
subject: How to wait in main method until all thread are finished
 
Similar Threads
JVM and Thread Help
Socket, Thread and synchronized
Threads and Synchronization examples
J@Whiz question
execute java app in servlet