managedthreadfactory

Naming threads and thread-pools of ExecutorService

ε祈祈猫儿з 提交于 2019-12-27 10:42:41
问题 Let's say I have an application that utilizes the Executor framework as such Executors.newSingleThreadExecutor().submit(new Runnable(){ @Override public void run(){ // do stuff } } When I run this application in the debugger, a thread is created with the following (default) name: Thread[pool-1-thread-1] . As you can see, this isn't terribly useful and as far as I can tell, the Executor framework does not provide an easy way to name the created threads or thread-pools. So, how does one go

Shutdown or Not Shutdown? in ExecutorService (Java8)

梦想的初衷 提交于 2019-12-14 01:46:53
问题 I am trying to understand the behaviour of the executor service relative to shutdown. The documentation says that the application won't terminate unless there is a shutdown() call - but in this simple example. It exits after one minute precisely. Any idea? Runnable r = new Runnable() { @Override public void run() { Print.println("do nothing"); } }; ThreadFactory TF = (Runnable run) -> new Thread(run); ExecutorService exec = Executors.newCachedThreadPool(TF); exec.submit(r); returns this: 11