Code example for AtomicInteger

0
 
    /** 
     * {@link ThreadFactory} which sets a meaningful name for the thread. 
     */ 
    private static class BackgroundLoaderThreadFactory implements ThreadFactory {
        private final AtomicInteger mCount = new AtomicInteger(1);
        private final String mTag;
 
        public BackgroundLoaderThreadFactory(String tag) {
            mTag = tag;
        } 
 
        public Thread newThread(final Runnable r) {
            Thread t =  new Thread(r, mTag + "-" + mCount.getAndIncrement());
 
            if (t.getPriority() != Thread.MIN_PRIORITY)
                t.setPriority(Thread.MIN_PRIORITY);
 
            return t;
        } 
    }