Java 可完成未来的命名线程
是否可以设置CompletableFuture创建的线程的名称格式?要在调试器上实现如下操作:Java 可完成未来的命名线程,java,multithreading,Java,Multithreading,是否可以设置CompletableFuture创建的线程的名称格式?要在调试器上实现如下操作: Thread[pool-1-my-named-thread-1] 您可以使用创建命名线程或出售命名线程的ExecutorService 默认情况下,CompletableFuture也使用ForkJoinPool,因此您还需要 您可以使用创建命名线程或出售命名线程的ExecutorService 默认情况下,CompletableFuture也使用ForkJoinPool,因此您还需要 对。您可以选
Thread[pool-1-my-named-thread-1]
您可以使用创建命名线程或出售命名线程的ExecutorService
默认情况下,CompletableFuture也使用ForkJoinPool,因此您还需要
您可以使用创建命名线程或出售命名线程的ExecutorService
默认情况下,CompletableFuture也使用ForkJoinPool,因此您还需要
对。您可以选择它创建的线程的名称:
AtomicInteger counter = new AtomicInteger();
ForkJoinPool.ForkJoinWorkerThreadFactory factory = pool -> {
ForkJoinWorkerThread thread =
ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
thread.setName("user6778654-" + counter.incrementAndGet());
return thread;
};
CompletableFuture<Void> future = CompletableFuture.runAsync(task,
new ForkJoinPool(Runtime.getRuntime().availableProcessors(),
factory, null, false));
}
AtomicInteger计数器=新的AtomicInteger();
ForkJoinPool.ForkJoinWorkerThreadFactory=池->{
ForkJoinWorker螺纹=
ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(池);
setName(“user6778654-”+counter.incrementAndGet());
返回线程;
};
CompletableFuture=CompletableFuture.runAsync(任务,
新的ForkJoinPool(Runtime.getRuntime().availableProcessors(),
工厂,空,假);
}
是。您可以选择它创建的线程的名称:
AtomicInteger counter = new AtomicInteger();
ForkJoinPool.ForkJoinWorkerThreadFactory factory = pool -> {
ForkJoinWorkerThread thread =
ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
thread.setName("user6778654-" + counter.incrementAndGet());
return thread;
};
CompletableFuture<Void> future = CompletableFuture.runAsync(task,
new ForkJoinPool(Runtime.getRuntime().availableProcessors(),
factory, null, false));
}
AtomicInteger计数器=新的AtomicInteger();
ForkJoinPool.ForkJoinWorkerThreadFactory=池->{
ForkJoinWorker螺纹=
ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(池);
setName(“user6778654-”+counter.incrementAndGet());
返回线程;
};
CompletableFuture=CompletableFuture.runAsync(任务,
新的ForkJoinPool(Runtime.getRuntime().availableProcessors(),
工厂,空,假);
}
Thread.currentThread().setName(“..”)
可以设置当前线程的名称。但您应该改为使用ThreadFactory
自动命名线程,例如通过Thread.currentThread()。setName(“…”)
可以设置当前线程的名称。但是您应该改为使用ThreadFactory
自动命名线程,例如通过