multithreading - gpars,命名线程

标签 multithreading grails

List<byte[]> outputBytes = []
GParsPool.withPool( ) {
            outputBytes = events.collectParallel{
                depositNoticeService.getDepositNotice( it.id )
            }
        }

我想为每个线程命名,以便可以在日志记录中对其进行监视,但是我看不到任何有关如何到达那里的文档。

最佳答案

尝试获取当前线程,然后可以更改或获取它的选项:

Thread.currentThread().getName()
Thread.currentThread().setName("NEW NAME")

我正在使用执行程序,下面的示例对我有用:
import java.util.concurrent.*
import javax.annotation.*


def threadExecute = Executors.newSingleThreadExecutor()
threadExecute.execute {
        log.info(Thread.currentThread().getName())
        log.info(Thread.currentThread().setName("NEW NAME"))
        log.info(Thread.currentThread().getName())
 }
 threadExecute.shutdown()

关于multithreading - gpars,命名线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33103339/

相关文章:

c# - ReaderWriterLockSlim LockRecursionPolicy.SupportsRecursion DeadLock

Python Tkinter While 线程

java - 如果我只想要一种在线程之间发出信号的方法,为什么我在哪个对象上使用 wait()/notify() 很重要?

c# - 报告线程进度的最佳方式

grails - 如何在Grails域对象中获得声明的属性?

grails - 寻求从最后的http交换保留参数以在将来的交换中使用的最佳方法?

c++ - 具有高多线程的 TBB 4.2 内存泄漏

java - 在 Grails 中使用 Hibernate Annotated Java 类时的日期问题

grails - 我应该在grails插件中的什么地方注册JSON编码器?

java - 在 Grails 应用程序中通过命令行执行外部程序