- public class Demo2_Thread {
- /**
- * @param args
- */
- public static void main(String[] args) {
- Thread t = new Thread() {
- public void run() {
- for (int i = 0; i < 20; i++) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.println("T1" + "\t" + i);
- }
- }
- };
- Thread t2 = new Thread() {
- public void run() {
- for (int i = 0; i < 10; i++) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.println("T2" + "\t" + i);
- }
- }
- };
- t.setDaemon(true);
- t.start();
- t2.start();
- }
- }
复制代码
上课的时候写的,希望能帮到你 |