Thread 併發執行例項

蒼狼搏鷹發表於2020-11-08

package com.mingri;

public class demo {
public static void main(String[] args) {
Thread a = new ThreadA();
Thread b = new ThreadB();
a.start();
b.start();
}

}

class ThreadA extends Thread {
@Override
public void run() {
for (int i = 0; i < 101; i++) {
System.out.println(i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

}

class ThreadB extends Thread {
@Override
public void run() {
for (char i = ‘a’; i <= ‘z’; i++) {
System.out.println(i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

}

相關文章