sahadat49

print 1 to 10 sleep 1000

Dec 19th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. //main
  2.  
  3. package create3;
  4.  
  5. public class Create3 {
  6.  
  7. public static void main(String[] args) {
  8. NumPrinter np1 = new NumPrinter();
  9. NumPrinter np2 = new NumPrinter();
  10. NumPrinter np3 = new NumPrinter();
  11.  
  12. np1.start();
  13. try{np1.join();} catch(Exception ex){
  14. np2.start();
  15. np3.start();
  16. }
  17. }
  18.  
  19. }
  20.  
  21.  
  22. //2nd class
  23.  
  24. package create3;
  25.  
  26. public class NumPrinter extends Thread{
  27. @Override
  28. public void run(){
  29. for(int i= 1;i<=10;i++){
  30. try{Thread.sleep(1000);} catch(Exception ex){};
  31. System.out.println(i);
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment