Guest User

Untitled

a guest
Feb 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. public class ThreadDemo {
  2.  
  3. public static void main(String[] args) {
  4. MyThread t = new MyThread(); // creating thread 1
  5. MyThread t1 = new MyThread(); // creating thread 1
  6.  
  7. t.start(); // starting the thread
  8. t1.start(); // starting the thread
  9. // t.run();
  10. // t1.run();
  11. }
  12.  
  13.  
  14. }
  15.  
  16. class MyThread extends Thread {
  17.  
  18. public void run(){
  19. for(int i =0;i<10;i++)
  20. {
  21. System.out.println(i);
  22. System.out.println(Thread.currentThread());
  23. try {
  24. Thread.sleep(100);
  25. } catch (InterruptedException e) {
  26. // TODO Auto-generated catch block
  27. e.printStackTrace();
  28. }
  29. }
  30. }
  31. }
Add Comment
Please, Sign In to add comment