<>lambda The derivation of :

* This is to avoid too many anonymous inner class definitions . public class lambdaTest { public static void main(String[]
args) { // TODO Auto-generated method stub new Thread(()->
// Parameters are written in brackets , If it is a parameter, you can omit the brackets and write the parameter directly System.out.println(" Learning at the same time ")).start();// A line of code can be omitted
new Thread(()->{ System.out.println(" Side cover "); }).start(); } }
<> Daemons

Is for the user thread service ,JVM Stop without waiting for the daemons to finish executing .

* default : User thread
* JVM Wait for the user thread to finish execution before it stops . public class DeamonTest { public static void main(String[
] args) { // TODO Auto-generated method stub God god=new God(); Yous you=new
Yous(); Thread t=new Thread(god); t.setDaemon(true);// take God Set as a daemon t.start();
// After the user thread is executed , There is no need to wait for the execution of the daemons to complete , The program may stop . new Thread(new Yous()).start(); } } class
Yous implements Runnable{ @Override public void run() { for(int i=1;i<=365*100;i
++) { System.out.println("happy life..."); } System.out.println("espire!"); } }
class God implements Runnable{ @Override public void run() { for(int i=1;i<=365*
100000;i++) { System.out.println("blessing...."); } } }
<> Using the game of tortoise and rabbit race to understand thread
public class Racer implements Runnable{ private String winner; @Override public
void run() { for(int steps = 1;steps<=100;steps++) { if(Thread.currentThread().
getName().equals("rabbit")&&(steps%10)==0) { try { Thread.sleep(100); } catch (
InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace()
; } } System.out.println(Thread.currentThread().getName()+"--->"+steps); if(
gameOver(steps)) { break; } } } private boolean gameOver(int steps) { if(winner
!=null) { return true; }else { if(steps==100) { winner=Thread.currentThread().
getName(); System.out.println("winner====>"+winner); return true; } } return
false; } public static void main(String[] args) { // TODO Auto-generated method
stub Racer racer=new Racer(); new Thread(racer,"rabbit").start(); new Thread(
racer,"tortoise").start(); } }

Technology