A direct call to run() will execute the method in the current thread, rather than in its own thread. So pm1.run() must return before pm2 is even created -- which is why the output is One, One, Two, Two.
But if we use start() instead of run(), then the thread will be put in a ready state, eligible for execution. So pm1.start() puts pm1 in a ready state, and pm2.start() puts pm2 in a ready state. At that point, they are separate threads, at the mercy of the platform-dependent scheduler. However, given the sleep and yield commands, it's a fairly "reasonable" expectation that these threads will alternate their execution and output One, Two, One, Two.
[ December 20, 2004: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com