I am getting following as o/ps at different time, for above code. 1>two one two one
2>one two one two
why so? the code is compiling perfectly. Thread of 'one' is starting 1st then how this o/p is getting executed ?s it bcoz both start() methods are together???(one below the other) but this can't be the ans?
hi shubha, i understand the reason for the inconsistent output is that when we call the start method on a thread is actually placed in a runnable state where it is eligible to be choosen by the scheduler for running(the actual state where the thread is alive). so, there is no garuntee that if a thread calls its start method first it will be executed then and there, it all depends on the scheduler. hope this helps to understand the reason for different outputs when the same code is run many times.