-1

Please answer my question need help.getting error recompile with xlint. Java uses or overrides deprecated API. This is the third time am trying to post this question and still not able to post if this question get posted this time please answer my question

class a extends Thread {
  public void run() {
    for(int i=1;i<=5;i++) {
      if(i==1) {
        yield();
      }
      System.out.println("message from a "+i);
    }
    System.out.println("exit from a");
  }
}

class b extends Thread {
  public void run() {
    for(int i=1;i<=5;i++) {
      System.out.println("message from b "+i);
      if(i==3)
        stop();
    }
    System.out.println("exit from b");
  }
}

class c extends Thread {
  public void run () {
    for(int i=1;i<=5;i++) {
      System.out.println("message from c" +i);
      if(i==1)
      try {
        sleep(1001); 
      }
      catch(Exception e) {
      }
    }
    System.out.println("exit from c");
  }
}

class threadsmethods {
  public static void main(String args []) {

    System.out.println("started Thread a");

    new a().start();

    System.out.println("Thread b started");

    new b().start();

    System.out.println("Thread c started");

    new c().start();

    System.out.println("end of main Thread");
  }
}
user187744
  • 71
  • 1
  • 1
  • 7

2 Answers2

1

Thread's stop method has been deprecated and hence you see warning.

If you just want to stop thread after 3 iteration, then you should break from loop and you will come out of run method which would stop your thread automatically. Instead of using stop use something like:

if(i==3)
    break;

Once loop would exit, that would make your thread exit gracefully.

SMA
  • 36,381
  • 8
  • 49
  • 73
0

In my case I just restart emulator and Everything worked out right.

Mohsen Hrt
  • 263
  • 2
  • 9