public class lazyMan {
Private lazyMan () {
System. Out. Println (Thread. CurrentThread (). The getName () + "OK");
}
Private static lazyMan lazyMan;
Public static lazyMan getInstance () {
If (lazyman==null) {
Lazyman=new lazyman ();
}
Return lazyman;
}
Public static void main (String [] args) {
for(int i=0; i<10; I++) {
New Thread (() - & gt; {
LazyMan. GetInstance ();
}).start();
}
}
}
The
new Thread (() - & gt; {
LazyMan. GetInstance ();
}).start();
to the lambda expressions, how to change?
CodePudding user response:
New Thread () {
@ Override
Public void the run () {
LazyMan. GetInstance ();
}
}. The start ();
CodePudding user response:
Public class lazyManThread extends Thread {
@ Override
Public void the run () {
LazyMan. GetInstance ();
}
}
Modify the main method under
LazyManThread thread=new lazyManThread ();
Thread. The run ();
CodePudding user response:
New Thread () {
@ Override
Public void the run () {
LazyMan. GetInstance ();
}
}. The start ();
CodePudding user response: