Example usage for java.lang Thread NORM_PRIORITY

List of usage examples for java.lang Thread NORM_PRIORITY

Introduction

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

Prototype

int NORM_PRIORITY

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

Click Source Link

Document

The default priority that is assigned to a thread.

Usage

From source file:org.geowebcache.seed.SeedTask.java

@Override
protected void doActionInternal() throws GeoWebCacheException, InterruptedException {
    super.state = GWCTask.STATE.RUNNING;

    // Lower the priority of the thread
    Thread.currentThread().setPriority((java.lang.Thread.NORM_PRIORITY + java.lang.Thread.MIN_PRIORITY) / 2);

    checkInterrupted();/*  w  w  w .ja  va2  s .  co  m*/

    // approximate thread creation time
    final long START_TIME = System.currentTimeMillis();

    final String layerName = tl.getName();
    log.info(Thread.currentThread().getName() + " begins seeding layer : " + layerName);

    TileRange tr = trIter.getTileRange();

    checkInterrupted();
    // TODO move to TileRange object, or distinguish between thread and task
    super.tilesTotal = tileCount(tr);

    final int metaTilingFactorX = tl.getMetaTilingFactors()[0];
    final int metaTilingFactorY = tl.getMetaTilingFactors()[1];

    final boolean tryCache = !reseed;

    checkInterrupted();
    long[] gridLoc = trIter.nextMetaGridLocation(new long[3]);

    long seedCalls = 0;
    while (gridLoc != null && this.terminate == false) {

        checkInterrupted();
        Map<String, String> fullParameters = tr.getParameters();

        ConveyorTile tile = new ConveyorTile(storageBroker, layerName, tr.getGridSetId(), gridLoc,
                tr.getMimeType(), fullParameters, null, null);

        for (int fetchAttempt = 0; fetchAttempt <= tileFailureRetryCount; fetchAttempt++) {
            try {
                checkInterrupted();
                tl.seedTile(tile, tryCache);
                break;// success, let it go
            } catch (Exception e) {
                // if GWC_SEED_RETRY_COUNT was not set then none of the settings have effect, in
                // order to keep backwards compatibility with the old behaviour
                if (tileFailureRetryCount == 0) {
                    if (e instanceof GeoWebCacheException) {
                        throw (GeoWebCacheException) e;
                    }
                    throw new GeoWebCacheException(e);
                }

                long sharedFailureCount = sharedFailureCounter.incrementAndGet();
                if (sharedFailureCount >= totalFailuresBeforeAborting) {
                    log.info("Aborting seed thread " + Thread.currentThread().getName()
                            + ". Error count reached configured maximum of " + totalFailuresBeforeAborting);
                    super.state = GWCTask.STATE.DEAD;
                    return;
                }
                String logMsg = "Seed failed at " + tile.toString() + " after " + (fetchAttempt + 1) + " of "
                        + (tileFailureRetryCount + 1) + " attempts.";
                if (fetchAttempt < tileFailureRetryCount) {
                    log.debug(logMsg);
                    if (tileFailureRetryWaitTime > 0) {
                        log.trace("Waiting " + tileFailureRetryWaitTime + " before trying again");
                        Thread.sleep(tileFailureRetryCount);
                    }
                } else {
                    log.info(logMsg + " Skipping and continuing with next tile. Original error: "
                            + e.getMessage());
                }
            }
        }

        if (log.isTraceEnabled()) {
            log.trace(Thread.currentThread().getName() + " seeded " + Arrays.toString(gridLoc));
        }

        // final long totalTilesCompleted = trIter.getTilesProcessed();
        // note: computing the # of tiles processed by this thread instead of by the whole group
        // also reduces thread contention as the trIter methods are synchronized and profiler
        // shows 16 threads block on synchronization about 40% the time
        final long tilesCompletedByThisThread = seedCalls * metaTilingFactorX * metaTilingFactorY;

        updateStatusInfo(tl, tilesCompletedByThisThread, START_TIME);

        checkInterrupted();
        seedCalls++;
        gridLoc = trIter.nextMetaGridLocation(gridLoc);
    }

    if (this.terminate) {
        log.info("Job on " + Thread.currentThread().getName() + " was terminated after " + this.tilesDone
                + " tiles");
    } else {
        log.info(Thread.currentThread().getName() + " completed (re)seeding layer " + layerName + " after "
                + this.tilesDone + " tiles and " + this.timeSpent + " seconds.");
    }

    checkInterrupted();
    if (threadOffset == 0 && doFilterUpdate) {
        runFilterUpdates(tr.getGridSetId());
    }

    super.state = GWCTask.STATE.DONE;
}

From source file:com.twotoasters.android.horizontalimagescroller.io.ImageCacheManager.java

protected ImageCacheManager(Context context) {
    this.context = context;
    for (int i = 0; i < N_THREADS; i++) {
        imageLoaderThreads[i] = new ImagesLoader();
        imageLoaderThreads[i].setPriority(Thread.NORM_PRIORITY - 1);
    }/*from  w  w w .j a v a 2  s .  c o  m*/
}

From source file:com.stimulus.archiva.incoming.IAPRunnable.java

public IAPRunnable(String threadName, IAPTestCallback testCallback, MailboxConnection connection,
        int intervalSecs, FetchMessageCallback callback) {
    logger.debug("iaprunnable constructor called");
    setDaemon(true);/*from w  w w . j  a  v a 2  s  .  co m*/
    setName(threadName);
    this.intervalSecs = intervalSecs;
    this.callback = callback;
    this.testCallback = testCallback;
    this.connection = connection;
    setPriority(Thread.NORM_PRIORITY);
}

From source file:ssk.porject.grouponclone.ImageListFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getActivity())
            .threadPriority(Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory()
            .diskCacheFileNameGenerator(new Md5FileNameGenerator()).diskCacheSize(50 * 1024 * 1024) // 50 Mb
            .tasksProcessingOrder(QueueProcessingType.LIFO).writeDebugLogs() // Remove for release app
            .build();/*from ww  w. j  a  v  a 2s .  c  o m*/
    // Initialize ImageLoader with configuration.
    ImageLoader.getInstance().init(config);

    options = new DisplayImageOptions.Builder().showImageOnLoading(R.drawable.ic_stub)
            .showImageForEmptyUri(R.drawable.ic_empty).showImageOnFail(R.drawable.ic_error).cacheInMemory(true)
            .cacheOnDisk(true).considerExifParams(true)
            //            .displayer(new RoundedBitmapDisplayer(20))
            .build();

}

From source file:org.nuxeo.ecm.core.redis.contribs.RedisClusterInvalidator.java

protected void createSubscriberThread() {
    String name = "RedisClusterInvalidatorSubscriber:" + repositoryName + ":" + nodeId;
    subscriberThread = new Thread(this::subscribeToInvalidationChannel, name);
    subscriberThread/*from  w ww.  j a v a2 s  .c  om*/
            .setUncaughtExceptionHandler((t, e) -> log.error("Uncaught error on thread " + t.getName(), e));
    subscriberThread.setPriority(Thread.NORM_PRIORITY);
    subscriberThread.start();
}

From source file:org.nuxeo.ecm.core.redis.contribs.RedisDBSClusterInvalidator.java

protected void createSubscriberThread() {
    subscribeLatch = new CountDownLatch(1);
    String name = "RedisDBSClusterInvalidatorSubscriber:" + repositoryName + ":" + nodeId;
    subscriberThread = new Thread(this::subscribeToInvalidationChannel, name);
    subscriberThread/*ww  w.java 2 s  . c o m*/
            .setUncaughtExceptionHandler((t, e) -> log.error("Uncaught error on thread " + t.getName(), e));
    subscriberThread.setPriority(Thread.NORM_PRIORITY);
    subscriberThread.start();
    try {
        if (!subscribeLatch.await(TIMEOUT_SUBSCRIBE_SECOND, TimeUnit.SECONDS)) {
            log.error("Redis channel subscripion timeout after " + TIMEOUT_SUBSCRIBE_SECOND
                    + "s, continuing but this node may not receive cluster invalidations");
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new RuntimeException(e);
    }
}

From source file:com.arkatay.yada.codec.AudioEncoder.java

protected AudioEncoder(Mixer mixer) {
    // Create a logger for this class
    log = LogFactory.getLog(getClass());

    this.mixer = mixer;

    // Create the thread
    thread = new Thread(this, "Tencoder");
    thread.setPriority((Thread.NORM_PRIORITY + Thread.MAX_PRIORITY) / 2);

    // Reset list
    resetChannelsList = new LinkedList<Integer>();

    pool = PacketPool.getPool();//from   ww  w.ja v  a 2 s  .  c  o  m

    // Start in state off
    state = STATE_OFF;
}

From source file:org.opencms.scheduler.CmsSchedulerThreadPool.java

/**
 * Create a new <code>CmsSchedulerThreadPool</code> with default values.
 * //from   w w w  .  ja v  a 2 s  .  c  o m
 * This will create a pool with 0 initial and 10 maximum threads running 
 * in normal priority.<p>
 * 
 * @see #CmsSchedulerThreadPool(int, int, int)
 */
public CmsSchedulerThreadPool() {

    this(0, 10, Thread.NORM_PRIORITY);
}

From source file:com.oakclub.android.base.OakClubApplication.java

public static void initImageLoader(Context context) {
    // This configuration tuning is custom. You can tune every option, you may tune some of them, 
    // or you can create default configuration by
    //  ImageLoaderConfiguration.createDefault(this);
    // method./*from   w w w .  jav  a  2  s  .  c o  m*/
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
            .threadPriority(Thread.NORM_PRIORITY - 1)
            //.denyCacheImageMultipleSizesInMemory()
            //.discCacheFileNameGenerator(new Md5FileNameGenerator())
            .tasksProcessingOrder(QueueProcessingType.FIFO)
            //            .enableLogging() // Not necessary in common
            .build();
    // Initialize ImageLoader with configuration.
    ImageLoader.getInstance().init(config);
}

From source file:com.linkedin.pinot.core.query.scheduler.resources.ResourceManager.java

/**
 * @param config configuration for initializing resource manager
 *///www  . j  a  v a 2s.c  o  m
public ResourceManager(Configuration config) {
    numQueryRunnerThreads = config.getInt(QUERY_RUNNER_CONFIG_KEY, DEFAULT_QUERY_RUNNER_THREADS);
    numQueryWorkerThreads = config.getInt(QUERY_WORKER_CONFIG_KEY, DEFAULT_QUERY_WORKER_THREADS);

    LOGGER.info("Initializing with {} query runner threads and {} worker threads", numQueryRunnerThreads,
            numQueryWorkerThreads);
    // pqr -> pinot query runner (to give short names)
    ThreadFactory queryRunnerFactory = new ThreadFactoryBuilder().setDaemon(false)
            .setPriority(QUERY_RUNNER_THREAD_PRIORITY).setNameFormat("pqr-%d").build();
    queryRunners = MoreExecutors
            .listeningDecorator(Executors.newFixedThreadPool(numQueryRunnerThreads, queryRunnerFactory));

    // pqw -> pinot query workers
    ThreadFactory queryWorkersFactory = new ThreadFactoryBuilder().setDaemon(false)
            .setPriority(Thread.NORM_PRIORITY).setNameFormat("pqw-%d").build();
    queryWorkers = MoreExecutors
            .listeningDecorator(Executors.newFixedThreadPool(numQueryWorkerThreads, queryWorkersFactory));
}