(Java 7 NIO.2) custom name for the watch service thread -
using nio.2 in java 7, when create watch service that:
watchservice watcher = filesystems.getdefault().newwatchservice(); then, background thread started, polling file system events within infinite loop. name of thread "thread-n" bit of nuisance when investigating thread dumps or during profiling sessions.
can change name of thread?
looking @ implementation, not seem possible directly. if don't mind little hack, can find thread , rename it.
something (//todo: put error checks in place):
set<thread> threadsbefore = thread.getallstacktraces().keyset(); watchservice ws = filesystems.getdefault().newwatchservice(); //i don't need wait here on machine ymmv set<thread> threadsafter = thread.getallstacktraces().keyset(); threadsafter.removeall(threadsbefore); thread wsthread = threadsafter.toarray(new thread[1])[0]; system.out.println("wsthread = " + wsthread); wsthread.setname("watchservice thread"); set<thread> justchecking = thread.getallstacktraces().keyset(); system.out.println("justchecking = " + justchecking);
Comments
Post a Comment