Example usage for java.lang Thread MIN_PRIORITY

List of usage examples for java.lang Thread MIN_PRIORITY

Introduction

In this page you can find the example usage for java.lang Thread MIN_PRIORITY.

Prototype

int MIN_PRIORITY

To view the source code for java.lang Thread MIN_PRIORITY.

Click Source Link

Document

The minimum priority that a thread can have.

Usage

From source file:net.sf.cindy.impl.SimpleEventGenerator.java

public void setPriority(int priority) throws IllegalArgumentException {
    if (priority < Thread.MIN_PRIORITY || priority > Thread.MAX_PRIORITY)
        throw new IllegalArgumentException();
    if (thread != null)
        thread.setPriority(priority);/*from  w  ww.  j a va 2s.c  o m*/
    this.priority = priority;
}

From source file:gda.gui.epics.EpicsMonitor.java

public void start() {
    if (!started) {
        Thread t = uk.ac.gda.util.ThreadManager.getThread(this);
        t.setPriority(java.lang.Thread.MIN_PRIORITY);
        t.start();/*from   w w  w. ja v  a2 s.  c o  m*/
        started = true;
    }
}

From source file:org.geowebcache.georss.GeoRSSPoller.java

/**
 * Upon instantiation, spawns out a thread after #{@code startUpDelaySecs} seconds that
 * periodically (at least every each layer's {@link GeoRSSFeedDefinition#getPollInterval() poll
 * interval} polls the layers feed for change sets and if changes are found spawns a reseed
 * process on the tiles affected by the change set.
 * //from  w  w  w.  ja v  a  2  s . co  m
 * @param seeder
 * @param startUpDelaySecs
 *            seconds to wait before start polling the layers
 */
public GeoRSSPoller(final TileBreeder seeder, final int startUpDelaySecs) {

    this.seeder = seeder;
    this.scheduledPolls = new ArrayList<PollDef>();
    this.scheduledTasks = new ArrayList<GeoRSSPollTask>();

    final int corePoolSize = 1;
    CustomizableThreadFactory tf = new CustomizableThreadFactory("GWC GeoRSS Poll Tasks-");
    tf.setDaemon(true);
    tf.setThreadPriority(Thread.MIN_PRIORITY + 1);
    schedulingPollExecutorService = Executors.newScheduledThreadPool(corePoolSize, tf);

    schedulingPollExecutorService.submit(new Runnable() {

        public void run() {
            logger.info("Initializing GeoRSS poller in a background job...");

            findEnabledPolls();

            if (pollCount() > 0) {

                final TimeUnit seconds = TimeUnit.SECONDS;
                for (PollDef poll : scheduledPolls) {
                    GeoRSSPollTask command = new GeoRSSPollTask(poll, seeder);
                    GeoRSSFeedDefinition pollDef = poll.getPollDef();
                    long period = pollDef.getPollInterval();

                    logger.info("Scheduling layer " + poll.getLayer().getName() + " to poll the GeoRSS feed "
                            + pollDef.getFeedUrl() + " every " + pollDef.getPollIntervalStr());

                    schedulingPollExecutorService.scheduleAtFixedRate(command, startUpDelaySecs, period,
                            seconds);

                    scheduledTasks.add(command);
                }
                logger.info("Will wait " + startUpDelaySecs + " seconds before launching the " + pollCount()
                        + " GeoRSS polls found");
            } else {
                logger.info("No enabled GeoRSS feeds found, poller will not run.");
            }
        }
    });
}

From source file:io.bitsquare.common.util.Utilities.java

public static ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor(String name, int corePoolSize,
        int maximumPoolSize, long keepAliveTimeInSec) {
    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(name).setDaemon(true)
            .setPriority(Thread.MIN_PRIORITY).build();
    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(corePoolSize, threadFactory);
    executor.setKeepAliveTime(keepAliveTimeInSec, TimeUnit.SECONDS);
    executor.allowCoreThreadTimeOut(true);
    executor.setMaximumPoolSize(maximumPoolSize);
    executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
    executor.setRejectedExecutionHandler((r, e) -> {
        log.debug("RejectedExecutionHandler called");
    });/*from ww  w.  java2s. c  o m*/
    return executor;
}

From source file:org.xwiki.wiki.internal.provisioning.DefaultWikiProvisioningJobExecutor.java

@Override
public void initialize() throws InitializationException {
    this.jobs = new HashMap<List<String>, WikiProvisioningJob>();

    // Setup jobs thread
    BasicThreadFactory factory = new BasicThreadFactory.Builder().namingPattern("XWiki provisioning thread")
            .daemon(true).priority(Thread.MIN_PRIORITY).build();
    this.jobExecutor = Executors.newCachedThreadPool(factory);
}

From source file:eu.interedition.collatex.tools.CollationServer.java

public CollationServer(int maxParallelCollations, int maxCollationSize, String dotPath) {
    this.collationThreads = Executors.newFixedThreadPool(maxParallelCollations, new ThreadFactory() {
        private final AtomicLong counter = new AtomicLong();

        @Override/*from  w ww .  j a v a 2 s.c om*/
        public Thread newThread(Runnable r) {
            final Thread t = new Thread(r, "collator-" + counter.incrementAndGet());
            t.setDaemon(true);
            t.setPriority(Thread.MIN_PRIORITY);
            return t;
        }
    });

    this.maxCollationSize = maxCollationSize;
    this.dotPath = dotPath;
}

From source file:com.onecase.chatroom.service.DataLayerService.java

private void startSendThread() {
    Thread t = new Thread() {
        @Override/* ww w  .ja va 2  s.  c  o m*/
        public void run() {
            Looper.prepare();
            sendDataHandler = new OCHandler(Looper.myLooper());
            Looper.loop();
        }
    };
    t.setPriority(Thread.MIN_PRIORITY);
    t.start();
    while (sendDataHandler == null)
        ;
}

From source file:cx.fbn.nevernote.threads.ENThumbnailRunner.java

@Override
public void run() {
    thread().setPriority(Thread.MIN_PRIORITY);

    logger.log(logger.MEDIUM, "ENThumbnail");
    while (keepRunning) {
        try {//w w  w. j  a  v a2s  .c o  m
            String work = workQueue.take();
            mutex.lock();
            if (work.startsWith("GET")) {
                String guid = work.replace("GET ", "");
                logger.log(logger.EXTREME, "Evernote?? guid = " + guid);

                QByteArray thumbnailData = getENThumbnailData(guid);
                if (thumbnailData == null) { // ??
                    logger.log(logger.EXTREME, "Evernote????");
                } else {
                    QPixmap thumbnail_p = new QPixmap();
                    thumbnail_p.loadFromData(thumbnailData);
                    logger.log(logger.EXTREME, "Evernote?????");
                    saveImage(thumbnail_p, guid);
                    registImage(thumbnailData, guid);
                }

                enThumbnailSignal.getENThumbnailFinished.emit(guid);
                logger.log(logger.EXTREME, "Evernote?? guid = " + guid);
            } else if (work.startsWith("STOP")) {
                logger.log(logger.MEDIUM, "ENThumbnail?");
                keepRunning = false;
            }
            mutex.unlock();
        } catch (InterruptedException e) {
            // TODO ??? catch 
            e.printStackTrace();
        }
    }
}

From source file:org.polymap.core.runtime.PolymapThreadPoolExecutor.java

public static PolymapThreadPoolExecutor newInstance() {
    // policy:/*from w w  w. j av a 2 s  . c  o m*/
    //   - first: spawn up to proc*6 threads (stopped when idle for 180s)
    //   - then: queue 3 times more jobs (for faster feeding workers)
    //   - then: block until queue can take another job
    //   - and/or: expand corePoolSize (via bounds checkecker thread)
    int procs = Runtime.getRuntime().availableProcessors();
    final int nThreads = procs * 6;
    final int maxThreads = nThreads * 5;

    // Proper queue bound semantics but just half the task througput of
    // LinkedBlockingQueue in PerfTest
    // BlockingQueue queue = new ArrayBlockingQueue( nThreads * 5 );

    // Fastest. But unfortunatelle does not limit the number of queued
    // task, which might result in OOM or similar problem.
    final LinkedBlockingQueue queue = new LinkedBlockingQueue( /*nThreads * 3*/ );

    // Slowest queue. Does not feed the workers well if pool size exeeds.
    // BlockingQueue queue = new SynchronousQueue();

    final PolymapThreadPoolExecutor result = new PolymapThreadPoolExecutor(nThreads, maxThreads, 3 * 60, queue);
    result.allowCoreThreadTimeOut(true);

    // async queue bounds checker for unbound LinkedQueue
    Thread boundsChecker = new Thread("ThreadPoolBoundsChecker") {
        public void run() {
            int bound = result.getCorePoolSize() * 3;
            while (queue != null) {
                try {
                    Thread.sleep(1000);
                    //                        log.info( "queued:" + queue.size() 
                    //                                + " - pool:" + result.getCorePoolSize() 
                    //                                + " - largest:" + result.getLargestPoolSize() 
                    //                                + " - completed:" + result.getCompletedTaskCount() );
                    // need more threads?
                    if (queue.size() > bound && result.getCorePoolSize() < maxThreads) {
                        int n = result.getCorePoolSize() + nThreads;
                        log.info("Thread Pool: increasing core pool size to: " + n);
                        result.setCorePoolSize(n);
                    }
                    // shrink down?
                    if (queue.isEmpty() && result.getActiveCount() == 0
                            && result.getCorePoolSize() > nThreads) {
                        log.info("Thread Pool: decreasing core pool size to: " + nThreads);
                        result.setCorePoolSize(nThreads);
                    }
                } catch (Throwable e) {
                    log.warn("", e);
                }
            }
        }
    };
    boundsChecker.setPriority(Thread.MIN_PRIORITY);
    boundsChecker.start();

    return result;
}

From source file:org.sonatype.nexus.proxy.attributes.upgrade.AttributeUpgraderThread.java

public AttributeUpgraderThread(final File legacyAttributesDirectory,
        final RepositoryRegistry repositoryRegistry, final int limiterTps,
        final NumberSequence numberSequence) {
    this.legacyAttributesDirectory = legacyAttributesDirectory;
    this.repositoryRegistry = repositoryRegistry;
    // set throttle controller
    this.throttleController = new FixedRateWalkerThrottleController(limiterTps, numberSequence, this);
    // to have it clearly in thread dumps
    setName("LegacyAttributesUpgrader");
    // to not prevent sudden reboots (by user, if upgrading, and rebooting)
    setDaemon(true);//  ww w . j av a  2s.co  m
    // to not interfere much with other stuff (CPU wise)
    setPriority(Thread.MIN_PRIORITY);
}