lambda表达式多线程,名称怎么继承

public class TestTicket {
public static void main(String[] args) {
Thread thread=new Thread("车站窗口");
Thread thread1=new Thread("网络");
Thread thread2=new Thread("黄牛");
new Thread(()->{
for (int i = 1; i <=10 ; i++) {
// String name=Thread.currentThread().getName();//获取当前线程的名称
System.out.println(Thread.currentThread().getName()+"抢到第"+i+"张票,还有"+(10-i)+"张票");
try {
Thread.sleep(500);//休眠
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
thread.start();
thread1.start();
thread2.start();
}
}

回答

不太清楚你想问的
是这意思?

Thread t=new Thread(()->{
            for (int i = 1; i <=10 ; i++) {
// String name=Thread.currentThread().getName();//获取当前线程的名称
                System.out.println(Thread.currentThread().getName()+"抢到第"+i+"张票,还有"+(10-i)+"张票");
                try {
                    Thread.sleep(500);//休眠
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            
        });
t.setName("名字");
t.start();
以上是lambda表达式多线程,名称怎么继承的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>