For my Android application, I use ScheduledThreadPoolExecutor instead of Timer because it is not affected by time changes.
With the Timer, you can create it by giving it a name. EX: Timer myTimer = new Timer(“TimerA”);
This is very convenient because when debugging using DDMS in the Threads view, I can see which exactly Threads are running… and use the name to trace back to my code.
However, using ScheduledThreadPoolExecutor, I can’t seem to give it a name. And so when debugging using Threads view in DDMS, I see something like: “pool-4-thread-1” which isn’t meaningful and I can’t trace back to my code with a name like that.
Can anyone help me with this?
The standard Java API doesn’t support naming ThreadPoolExecutor, however, naming the Thread created by ThreadPoolExecutor is supported via ThreadFactory, check out here:
Sample code:
Hope this helps.