Problem in Multithreading ,,....
-
sir/mam i need to know the working of join() .... i tried books and net but i didn't got it. Please tell me exactly why we use join() function and what happens when we call the join().. Thanks
-
sir/mam i need to know the working of join() .... i tried books and net but i didn't got it. Please tell me exactly why we use join() function and what happens when we call the join().. Thanks
To be fair, the javadoc for this method isn't very clear:
Waits for this thread to die.
That's it. Not the most helpful javadoc I've ever seen. The Oracle Java tutorial[^] is better:
The join method allows one thread to wait for the completion of another. If t is a Thread object whose thread is currently executing,
t.join();
causes the current thread to pause execution until t's thread terminates.
I think that's quite clear and succinct.
-
is google down again? http://www.java-samples.com/showtutorial.php?tutorialid=301[^] can't explain it better.
regards Torsten I never finish anyth...
I tried to follow this link and got a security warning that the website was trying to open a program on my computer. No idea what it was or why, but that sort of thing makes me nervous.
-
I tried to follow this link and got a security warning that the website was trying to open a program on my computer. No idea what it was or why, but that sort of thing makes me nervous.
-
To be fair, the javadoc for this method isn't very clear:
Waits for this thread to die.
That's it. Not the most helpful javadoc I've ever seen. The Oracle Java tutorial[^] is better:
The join method allows one thread to wait for the completion of another. If t is a Thread object whose thread is currently executing,
t.join();
causes the current thread to pause execution until t's thread terminates.
I think that's quite clear and succinct.
-
sir/mam i need to know the working of join() .... i tried books and net but i didn't got it. Please tell me exactly why we use join() function and what happens when we call the join().. Thanks
To ensure that a thread (referenced by some reference say threadRef) is finished, then you join() on that reference. like threadRef.join() if that thread is finished, then join() returned immediately otherwise join() will blocked until that thread get finished. For example if you create three thread (a, b, c) for doing three different task A, B, C, from your main thread, but you need some initialization processing (which must be executed before start-up of a, b, c) and shutdown processing (which must be executed after finishing of a, b, c) then you may code like this // in main() System.out.println("System started"); initialization(); // a, b, c are not running yet. System.out.println("initialization complete "); Thread a = new Thread(new Task_A_RunnableClass()); Thread b = new Thread(new Task_B_RunnableClass()); Thread c = new Thread(new Task_C_RunnableClass()); a.start(); System.out.println("Thread "a" started "); b.start(); System.out.println("Thread "b" started "); c.start(); System.out.println("Thread "c" started "); //Now wait for all thread to finished. a.join(); System.out.println("Thread "a" finiished "); b.join(); System.out.println("Thread "b" finiished "); c.join(); System.out.println("Thread "c" finiished "); shutdown(); // a, b, c are finished now. System.out.println("System shutdown..... ");