给线程命名

package service;

import java.util.stream.IntStream;

/**
* @description: 给线程命名
* @author:
* @create:
**/

public class NamedThreads {
public static final String PREFIX = "NO-";

public static void main(String[] args) {
IntStream.range(0, 5).boxed().map(NamedThreads::createThread).forEach(Thread::start);
}

private static Thread createThread(final int intName){
return new Thread(() -> System.out.println(Thread.currentThread().getName()),
PREFIX + intName);
}
}
posted @ 2018-08-14 11:19  深渊中的鱼  阅读(702)  评论(0编辑  收藏  举报