首页 > 代码库 > java线程用法

java线程用法

package com;public class Demo {    public static void main(String[] args) {        // TODO Auto-generated method stub                //方法1        Thread t = new Thread() {            public void run() {                for (int i = 1; i <= 5; i++) {                    System.out.print(i + " ");                }            }        };        t.start();        System.out.print("\r\n");        //方法2                Runnable r = new Runnable() {            public void run() {                for (int i = 1; i <= 5; i++) {                    System.out.print(i + " ");                }            }        };        Thread t1 = new Thread(r);        t1.start();    }    }

 

java线程用法