java并发基础多线程学习(1)-线程创建两种方式

一:创建线程的两种方式:

(1)

Thread thread1 = new Thread(){
            public void run(){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName());
            }
        };
        thread1.start();









(2)

Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName());
            }
        });
        thread1.start();

猜你喜欢

转载自blog.csdn.net/liyingying111111/article/details/88863604