1 Reply Latest reply on Dec 12, 2012 6:19 AM by Kayaman

    What is the execution flow off the below program??

      When I tried to execute the below program ,
      class A extends Thread{
      int count = 0;
      public void run(){
      synchronized (this) {
      for(int i =0; i < 50 ; i++){
      count = count + i;
      public class q7146{
      public static void main(String argv[]) {
      A a = new A();
      synchronized (a) {
           }catch(InterruptedException e){

      The output was waiting run 1225
      When I uncomment the line System.out.println("started");
      The output is started run waiting 1225

      One single line in has introduced change in the odrer of priniting 'waiting' and 'run'.

      So what is the low of execution in the program and waht is the logic behind this. Please somebody explain this.

      Thankx for the help in advance.
        • 1. Re: What is the execution flow off the below program??
          First of all, put your code between
           tags so it formats correctly.
          Secondly, try running the program a few times and see whether you get consistent results.
          Thirdly, do your own homework.