Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ThreadTest
- {
- public static void main(String[] args) throws Exception
- {
- System.out.println("Hello World!");
- ThreadTest tt=new ThreadTest();
- tt.go();
- }
- public void go() throws Exception{
- Thread t=new Thread(new A());
- t.start();
- }
- class A implements Runnable
- {
- Thread t2=new Thread(new B());
- public void run(){
- int i=0;
- t2.start();
- while (i<10)
- {
- System.out.println(i);
- i++;
- }
- }
- }
- class B implements Runnable
- {
- int i=0;
- public void run(){
- while (i<10)
- {
- System.out.println(i);
- try {
- Thread.sleep(500);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- i++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment