产生线程:继承Thread和实现Runnable
直接上代码
package com.lyj; public class TraditionalThreadDemo1 { public static void main(String[] args) { Thread thread1 = new Thread() { @Override public void run() { super.run(); while (true) { try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Thread1: " + Thread.currentThread().getName()); } } }; thread1.start(); Thread thread2 = new Thread(new Runnable() { @Override public void run() { while (true) { try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Thread2: " + Thread.currentThread().getName()); } } }); thread2.start(); } }