Advertisement
Utshaw

Thread6

Oct 6th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. package intropackage;
  2.  
  3.  
  4. public class Driver {
  5. public static void main(String[] args) throws InterruptedException {
  6.  
  7. myThread thread = new myThread();
  8. thread.start();
  9. thread.interrupt(); //Thread.currentThread() causes interruption to myThread
  10. System.out.println("END OF MAIN THREAD");
  11.  
  12.  
  13. }
  14. }
  15. public class myThread extends Thread {
  16.  
  17.  
  18. @Override
  19. public void run() {
  20. try {
  21. for(int i=0;i<10;i++)
  22. {
  23. System.out.println("CHILD THREAD-"+i);
  24. Thread.sleep(1000);
  25. }
  26. } catch (InterruptedException e) {
  27. System.out.println("I am Interrupted ");
  28. }
  29.  
  30.  
  31. }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement