Example usage for java.util.concurrent ThreadFactory ThreadFactory

List of usage examples for java.util.concurrent ThreadFactory ThreadFactory

Introduction

In this page you can find the example usage for java.util.concurrent ThreadFactory ThreadFactory.

Prototype

ThreadFactory

Source Link

Usage

From source file:com.lightbox.android.bitmap.BitmapFileCleanerTask.java

private static ExecutorService getExecutor() {
    if (sBitmapFileCleanerExecutor == null) {
        sBitmapFileCleanerExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
            @Override/*w  ww.  ja  v a  2 s .  c o  m*/
            public Thread newThread(Runnable r) {
                Thread thread = new Thread(r);
                thread.setName(TAG + " | " + thread.getName());
                thread.setPriority(Thread.MIN_PRIORITY);
                return thread;
            }
        });
    }
    return sBitmapFileCleanerExecutor;
}

From source file:Main.java

public static ThreadFactory newNamedThreadFactory(final String name) {
    return new ThreadFactory() {
        @Override//from   w w  w .  jav a2 s. c o m
        public Thread newThread(final Runnable r) {
            Thread t = new Thread(r);
            t.setName(name);
            return t;
        }
    };
}

From source file:Main.java

public static ThreadFactory newGenericThreadFactory(final String processName, final boolean isDaemon) {
    return new ThreadFactory() {
        private AtomicInteger threadIndex = new AtomicInteger(0);

        @Override//from  w  w w.  ja  v a 2  s  .  c  o  m
        public Thread newThread(Runnable r) {
            Thread thread = new Thread(r,
                    String.format("%s_%d", processName, this.threadIndex.incrementAndGet()));
            thread.setDaemon(isDaemon);
            return thread;
        }
    };
}

From source file:com.snappydb.snippets.app.fragment.BaseExecutionFragment.java

@Override
public void onStart() {
    super.onStart();
    mExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
        @Override// w  w w . j a  v a2  s .com
        public Thread newThread(@NonNull Runnable runnable) {
            Thread thread = new Thread(runnable);
            thread.setPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
            return thread;
        }
    });

    try {
        mSnappyDB = new SnappyDB.Builder(getActivity()).name(getClass().getSimpleName()).build();

    } catch (SnappydbException e) {
        e.printStackTrace();
        throw new IllegalStateException("Can't create database");
    }
}

From source file:Main.java

public static ThreadFactory daemonThreadFactory(final String name) {
    return new ThreadFactory() {
        private int nextId = 0;

        public synchronized Thread newThread(Runnable r) {
            Thread thread = new Thread(r, name + "-" + (nextId++));
            thread.setDaemon(true);//from w  w w . j  av  a  2  s  . co m
            return thread;
        }
    };
}

From source file:Main.java

public static ThreadFactory getThreadFactory(final String name, final UncaughtExceptionHandler handler) {
    return new ThreadFactory() {
        @Override//w w w .ja v  a 2s .  c  o  m
        public Thread newThread(Runnable r) {
            Thread t = new Thread(null, r, name, 1024 * 1024);
            t.setDaemon(true);
            t.setUncaughtExceptionHandler(handler);
            return t;
        }
    };
}

From source file:com.google.zxing.client.android.result.supplement.SupplementalInfoRetriever.java

private static synchronized ExecutorService getExecutorService() {
    if (executorInstance == null) {
        executorInstance = Executors.newCachedThreadPool(new ThreadFactory() {
            public Thread newThread(Runnable r) {
                Thread t = new Thread(r);
                t.setDaemon(true);//from  www. j a v  a  2s. c  om
                return t;
            }
        });
    }
    return executorInstance;
}

From source file:org.apache.synapse.aspects.flow.statistics.log.StatisticEventProcessor.java

public static void initializeCleaningThread() {
    //Thread to consume queue and update data structures for publishing
    ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setName("Mediation Statistic Stale Entry Cleaning Task");
            return t;
        }/*from  w  w  w.  j  av a  2 s  . c  o  m*/
    });
    Long eventCleanTime = Long.parseLong(
            SynapsePropertiesLoader.getPropertyValue(StatisticsConstants.FLOW_STATISTICS_EVENT_CLEAN_TIME,
                    StatisticsConstants.FLOW_STATISTICS_DEFAULT_EVENT_CLEAN_INTERVAL));
    StatisticCleaningThread statisticCleaningThread = new StatisticCleaningThread(runtimeStatistics);
    executor.scheduleAtFixedRate(statisticCleaningThread, 0, eventCleanTime, TimeUnit.MILLISECONDS);
}

From source file:com.espertech.esper.epl.metric.MetricsExecutorThreaded.java

/**
 * Ctor.// w ww  . ja v a  2 s  .c  om
 * @param engineURI engine URI
 */
public MetricsExecutorThreaded(final String engineURI) {
    ThreadFactory threadFactory = new ThreadFactory() {
        AtomicInteger count = new AtomicInteger(0);

        public Thread newThread(Runnable r) {
            String uri = engineURI;
            if (engineURI == null) {
                uri = "default";
            }
            Thread t = new Thread(r);
            t.setName("com.espertech.esper.MetricReporting-" + uri + "-" + count.getAndIncrement());
            t.setDaemon(true);
            return t;
        }
    };
    threadPool = Executors.newCachedThreadPool(threadFactory);
}

From source file:org.apache.synapse.commons.throttle.core.ThrottleContextCleanupTask.java

public ThrottleContextCleanupTask() {

    ScheduledExecutorService executor = Executors.newScheduledThreadPool(1, new ThreadFactory() {

        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setName("Throttle Cleanup Task");
            return t;
        }/*from  w  ww  .  j a va 2 s .  co m*/
    });

    String throttleFrequency = System.getProperty(THROTTLE_CONTEXT_CLEANUP_TASK_FREQUENCY);
    if (throttleFrequency == null) {
        throttleFrequency = "3600000";
    }

    if (log.isDebugEnabled()) {
        log.debug("Throttling Cleanup Task Frequency set to " + throttleFrequency);
    }

    executor.scheduleAtFixedRate(new CleanupTask(), Integer.parseInt(throttleFrequency),
            Integer.parseInt(throttleFrequency), TimeUnit.MILLISECONDS);

}