Creator

ThreadTest

Dec 11th, 2011
976
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. public class  ThreadTest
  2. {
  3.     public static void main(String[] args) throws Exception
  4.     {
  5.         System.out.println("Hello World!");
  6.         ThreadTest tt=new ThreadTest();
  7.         tt.go();
  8.  
  9.     }
  10.     public void go() throws Exception{
  11.         Thread t=new Thread(new A());
  12.         t.start();
  13.     }
  14.  
  15.     class A implements Runnable
  16.     {
  17.         Thread t2=new Thread(new B());
  18.         public void run(){
  19.             int i=0;
  20.             t2.start();
  21.             while (i<10)
  22.             {
  23.  
  24.                 System.out.println(i);
  25.                
  26.                 i++;
  27.  
  28.             }
  29.         }
  30.     }
  31.     class B implements Runnable
  32.     {
  33.         int i=0;
  34.         public void run(){
  35.             while (i<10)
  36.             {
  37.                 System.out.println(i);
  38.                 try {
  39.                     Thread.sleep(500);
  40.                 } catch (InterruptedException e) {
  41.                     e.printStackTrace();
  42.                 }
  43.                 i++;
  44.             }
  45.         }
  46.     }
  47. }
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment