This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
My understanding was that if I invoke run()from a thread object directly this would be legal but not create a new call stack or a new thread.
So I wrote the following:
And invoked run() as below....
But I got output:
run: Invocation : 0: current thread = Thread[Thread-0,5,main] Invocation : 1: current thread = Thread[Thread-1,5,main] END BUILD SUCCESSFUL (total time: 0 seconds)
If I take away the for loop delay statement, I can see the third display from the direct run() call in the main thread. If I put the delay in then I only get two lines as above. I expected to see all three displays as below (in maybe a different order) even with the delay.
run: Invocation : 0: current thread = Thread[main,5,main] END Invocation : 1: current thread = Thread[Thread-0,5,main] Invocation : 2: current thread = Thread[Thread-1,5,main] BUILD SUCCESSFUL (total time: 0 seconds)
Can anyone explain why this didn't happen? Thanks. -Tom
If I take away the for loop delay statement, I can see the third display from the direct run() call in the main thread. If I put the delay in then I only get two lines as above. I expected to see all three displays as below (in maybe a different order) even with the delay.
If you invoke the run() method directly, the thread object will "not create a new call stack or a new thread". However, keep in mind that you did not override the thread object's run() method. The thread object's run() method is not necessaryly your runnable's run() method.
The thread object's run() method which will check the state of the thread, and call runnable's run() method. By putting in the delay, you are making sure that the thread is no longer in a runnable state, and hence, will not call your run() method.
If you want to call the run() method, use "r.run()" -- don't play with the thread's internal methods.
run() method, use "r.run()" -- don't play with the thread's internal methods.
Rest assured I'd only code this to see what happens - like the time I bent Dad's fishing rod a just a little bit too much to see what a big fish would do...