2015-10-13 56 views
0
List<byte[]> outputBytes = [] 
GParsPool.withPool() { 
      outputBytes = events.collectParallel{ 
       depositNoticeService.getDepositNotice(it.id) 
      } 
     } 

我想命名每个线程,所以我可以在日志中监视它,但我没有看到有关如何到达那里的任何文档。Gpars,线程的名称

回答

1

尝试获取当前线程,比你可以更改或得到它的选项:

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

我使用Executors这里的例子,对我的作品:

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()