(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

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -