package com.neu.day01;
public class Thread01 {
public static void main(String[] args) {
//jdk 1.8之前匿名类部类
new Thread("new01"){
public void run() {
browseNews();
}
}.start();
//jdk 1.8 Lambda编码方式
Thread thread = new Thread(() -> {
browseNews();
});
thread.setName("news2");
thread.start();
Thread thread1 = new Thread(Thread01::enjoyMusic);
thread1.setName("music");
thread1.start();
}
private static void browseNews(){
while (true){
System.out.println("The good news");
try{
Thread.sleep(1000);
}catch (Exception e){
e.printStackTrace();
}
}
}
private static void enjoyMusic(){
while (true){
System.out.println("The good music");
try{
Thread.sleep(1000);
}catch (Exception e){
e.printStackTrace();
}
}
}
}
终端操作
jconsole观察线程