timer - Android Debugging ScheduledThreadPoolExecutor using DDMS -
for android application, use scheduledthreadpoolexecutor instead of timer because not affected time changes.
with timer, can create giving name. ex: timer mytimer = new timer("timera");
this convenient because when debugging using ddms in threads view, can see threads running... , use name trace code.
however, using scheduledthreadpoolexecutor, can't seem give name. , when debugging using threads view in ddms, see like: "pool-4-thread-1" isn't meaningful , can't trace code name that.
can me this?
the standard java api doesn't support naming threadpoolexecutor, however, naming thread created threadpoolexecutor supported via threadfactory, check out here:
creating new threads
new threads created using threadfactory. if not otherwise specified, defaultthreadfactory() used, creates threads in same threadgroup , same norm_priority priority , non-daemon status. supplying different threadfactory, can alter thread's name, thread group, priority, daemon status, etc. if threadfactory fails create thread when asked returning null newthread, executor continue, might not able execute tasks.
sample code:
scheduledthreadpoolexecutor scheduledthreadpoolexecutor = executors.newscheduledthreadpool(5, new threadfactory() { final atomicinteger threadnumber = new atomicinteger(1); @override public thread newthread(runnable r) { return new thread(r, "foo-" + threadnumber.getandincrement()); } }); hope helps.
Comments
Post a Comment