0

multi threading in java

Hello Everyone, Please review this program and suggest. It is working as expected. class Loader extends Thread { public void run() { System.out.println("in Loader program"); try{ Thread.sleep(1000); System.out.println("end of Loader class"); } catch(Exception e){ System.out.println("IE!"); } } } class Loader1 implements Runnable { public void run() { System.out.println("in loader1 class"); System.out.println("end of loader1"); } } class MyClass { public static void main(String[ ] args) { Loader obj = new Loader(); System.out.println("Loader class object [obj] is created & calling start on obj of Loader class"); obj.start(); System.out.println("called start on obj of Loader class and it is in progress"); Thread obj1 = new Thread(new Loader1()); System.out.println("Loader1 object [obj1] is created and calling start menthod on obj1 of Loader1 class"); obj1.start(); System.out.println("called start on obj1 of Loader1 class and it is in progress"); } } output: Loader class object [obj] is created & calling start on obj of Loader class called start on obj of Loader class and it is in progress Loader1 object [obj1] is created and calling start menthod on obj1 of Loader1 class called start on obj1 of Loader1 class and it is in progress in Loader program in loader1 class end of loader1 end of Loader class

9th Feb 2018, 7:28 AM
Tech guide 2020@youtube [premmengani]
Tech guide 2020@youtube [premmengani] - avatar
1 Resposta
+ 2
It seems that the output is correct bro 👍. I don't remember if sleep(long ms) is deprecated or not, because of the method wait(). But I think the correct way to call a Thread is Runnable obj = new Loader() ; Thread t = new Thread(obj) ; t.start();
9th Feb 2018, 7:34 AM
Leonardo Medai Cossutta
Leonardo Medai Cossutta - avatar