Java thread creation problem

CSDN Q & A 2022-02-13 07:20:14 阅读数:676

java thread creation problem

img
This is a java How to create threads ? It's weird




Take the answer :

new Thread(Runnable runnable) In this construction method Runnable It's a functional interface , There must be only one way , If there are two ways , You can't do this ()-> or Test::test It's written like this .

img

Please accept please accept please accept please accept please accept please accept please accept please accept



Other answers 2:

java8 Medium Lambda Expression writing


Other answers 3:

This Test::test yes Lambda Method calls in expressions , You can understand it as Test::test => new Test().test();
This is a wrong implementation , If you want to use Lambda Expression writing , Then you need to write anonymous inner classes. Examples are as follows

new Thread(() -> { System.out.println(Thread.currentThread().getName());}).start();

Other answers 4:

jvm No ability to create threads , In fact, they all call the underlying operating system to complete the creation and startup of threads

copyright:author[CSDN Q & A],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130720126937.html