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:net.reichholf.dreamdroid.DreamDroid.java

public static void initImageLoader(Context context) {
    if (ImageLoader.getInstance().isInited())
        return;/* w w w .j  a va  2 s. co m*/
    // 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.
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
            .threadPoolSize(java.lang.Runtime.getRuntime().availableProcessors())
            .threadPriority(Thread.NORM_PRIORITY - 2).discCacheFileNameGenerator(new Md5FileNameGenerator())
            .tasksProcessingOrder(QueueProcessingType.FIFO).build();
    // Initialize ImageLoader with configuration.
    ImageLoader.getInstance().init(config);
}

From source file:org.eclipse.gyrex.jobs.internal.scheduler.Schedule.java

synchronized void activateEngine() {
    if (JobsDebug.schedulerEngine) {
        LOG.debug("Activating schedule {}...", scheduleStoreStorageKey);
    }//from w w  w . ja  va  2s . c  o m
    if (null != quartzScheduler)
        return;

    try {
        // make sure that Quartz does not check for updates
        System.setProperty("org.terracotta.quartz.skipUpdateCheck", "true");

        // prepare scheduler 
        final DirectSchedulerFactory factory = DirectSchedulerFactory.getInstance();
        final SimpleThreadPool threadPool = new SimpleThreadPool(1, Thread.NORM_PRIORITY);
        threadPool.setInstanceId(scheduleStoreStorageKey);
        threadPool.setInstanceName(scheduleStoreStorageKey);
        final JobStore jobStore = new RAMJobStore();

        // create scheduler
        // (make sure that only a single thread manipulates the SchedulerRepository)
        final SchedulerRepository repository = SchedulerRepository.getInstance();
        synchronized (repository) {
            factory.createScheduler(scheduleStoreStorageKey, scheduleStoreStorageKey, threadPool, jobStore);
            quartzScheduler = factory.getScheduler(scheduleStoreStorageKey);
            if (null == quartzScheduler) {
                quartzScheduler = repository.lookup(scheduleStoreStorageKey);
            }
        }

        // double check to ensure that Quartz did not fail
        if (null == quartzScheduler)
            throw new SchedulerException(
                    "Unabled to retrieve created scheduler from Quartz SchedulerRepository. It looks like the creation failed but the Quartz framework did not report it as such!");

        // TODO add support for calendars (we likely should support global calendars)

        // refresh the schedule
        refreshSchedule();

        // start
        quartzScheduler.start();
        metrics.setStatus("QUARTZRUNNING", "Quartz schedule started successfully");

        // log success message
        LOG.info("Activated schedule {}.", getScheduleStoreStorageKey());
    } catch (final SchedulerException e) {
        LOG.error("Unable to activate Quarz scheduler. {}", ExceptionUtils.getRootCauseMessage(e));
        metrics.error("error activating schedule", e);

        // cleanup
        quietShutdown();
    }

}

From source file:org.opencms.search.CmsLuceneIndexWriter.java

/**
 * @see org.opencms.search.I_CmsIndexWriter#optimize()
 * /*from  w  w  w.  j  a va  2  s.c om*/
 * As optimize is deprecated with Lucene 3.5, this implementation 
 * actually calls {@link IndexWriter#forceMerge(int)}.<p>
 */
public void optimize() throws IOException {

    if ((m_index != null) && LOG.isInfoEnabled()) {
        LOG.info(Messages.get().getBundle().key(Messages.LOG_INDEX_WRITER_MSG_OPTIMIZE_2, m_index.getName(),
                m_index.getPath()));
    }
    int oldPriority = Thread.currentThread().getPriority();
    // we don't want the priority too low as the process should complete as fast as possible
    Thread.currentThread().setPriority(Thread.NORM_PRIORITY / 2);
    m_indexWriter.forceMerge(5);
    Thread.currentThread().setPriority(oldPriority);
}

From source file:net.NettyEngine3.core.NServerFrameNettyStart.java

/**
 * main_reactor and  sub_reactor/*  ww w.  j  a  va  2s.co m*/
 * @return
 */
@Override
public Bootstrap getServerBootstrap() {
    ChannelFactory factory = new NioServerSocketChannelFactory(
            Executors.newFixedThreadPool(0x1,
                    new PriorityThreadFactory("@+main_reactor+@", Thread.NORM_PRIORITY)),
            Executors.newCachedThreadPool(
                    new PriorityThreadFactory("@+sub_reactor+@", Thread.NORM_PRIORITY)));
    bootstrap = new ServerBootstrap(factory);
    return bootstrap;
}

From source file:com.workplacesystems.queuj.utils.BackgroundProcess.java

/** start is used to start the processing. run() is called directly if this is a child process 
 * or in a separate thread if this is a parent process. */
public final Object start() {
    return start(Thread.NORM_PRIORITY);
}

From source file:com.clustercontrol.poller.impl.UdpTransportMappingImpl.java

/**
 * Returns the priority of the internal listen thread.
 * //  w w w  . ja  v a 2  s. co  m
 * @return a value between {@link Thread#MIN_PRIORITY} and
 *         {@link Thread#MAX_PRIORITY}.
 * @since 1.2.2
 */
public int getPriority() {
    WorkerTask lt = listener;
    if (lt instanceof Thread) {
        return ((Thread) lt).getPriority();
    } else {
        return Thread.NORM_PRIORITY;
    }
}

From source file:net.NettyEngine4.ServerServiceImpl.java

/**
 * jni native Epoll/*from ww  w  . jav a  2s .  c o m*/
 #NioEventLoopGroup  EpollEventLoopGroup   ---- EventLoopGroup ?
 #NioEventLoop  EpollEventLoop
 #NioServerSocketChannel  EpollServerSocketChannel
 #NioSocketChannel  EpollSocketChannel        ---- SocketChannel?
        
 ## RHEL/CentOS/Fedora:
 #sudo yum install autoconf automake libtool glibc-devel.i686 glibc-devel libgcc.i686 make
 ## Debian/Ubuntu:
 #sudo apt-get install autoconf automake libtool make gcc-multilib
 * @throws Exception
 */
@Override
public void runNativeEpoll() throws Exception {
    EpollEventLoopGroup BossEventLoopGroup = new EpollEventLoopGroup(0x1,
            new PriorityThreadFactory("@+?", Thread.NORM_PRIORITY)); //mainReactor    1
    EpollEventLoopGroup WorkerEventLoopGroup = new EpollEventLoopGroup(
            Runtime.getRuntime().availableProcessors() + 0x1,
            new PriorityThreadFactory("@+I/O", Thread.NORM_PRIORITY)); //subReactor       ?cpu+1
    ServerBootstrap serverBootstrap = new ServerBootstrap();
    try {
        serverBootstrap.group(BossEventLoopGroup, WorkerEventLoopGroup).channel(EpollServerSocketChannel.class)
                .childOption(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_KEEPALIVE, true)
                .childOption(ChannelOption.SO_REUSEADDR, true) //??
                .childOption(ChannelOption.ALLOCATOR, new PooledByteBufAllocator(false))// heap buf 's better
                .childOption(ChannelOption.SO_RCVBUF, 1048576).childOption(ChannelOption.SO_SNDBUF, 1048576)
                .childHandler(new ServerChannelInitializer());//used to serve the request for the {@link Channel}'s
        // Bind and start to accept incoming connections.
        ChannelFuture channelFuture = serverBootstrap
                .bind(new InetSocketAddress(Config.DEFAULT_VALUE.SERVER_VALUE.gameserverPort)).sync();
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("server??:" + Config.DEFAULT_VALUE.SERVER_VALUE.gameserverPort);
        // Wait until the server socket is closed.
        // In this server, this does not happen, but you can do that to gracefully
        // shut down your server.
        channelFuture.channel().closeFuture().sync();
    } finally {
        // Shut down all event loops to terminate all threads.
        BossEventLoopGroup.shutdownGracefully();
        WorkerEventLoopGroup.shutdownGracefully();
    }
}

From source file:com.miqtech.master.client.ui.ImagePagerActivity.java

public 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   www.  ja v a 2 s.  c o m*/
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
            .threadPriority(Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory()
            .discCacheFileNameGenerator(new Md5FileNameGenerator())
            .tasksProcessingOrder(QueueProcessingType.LIFO).writeDebugLogs() // Remove for release app
            .build();
    // Initialize ImageLoader with configuration.
    ImageLoader.getInstance().init(config);
}

From source file:org.ebayopensource.winder.quartz.QuartzSchedulerManager.java

private void init() {
    WinderConfiguration configuration = engine.getConfiguration();
    DirectSchedulerFactory factory = DirectSchedulerFactory.getInstance();
    int numThreads = configuration.getInt("winder.quartz.numThreads", 50);

    String quartzType = configuration.getString("winder.quartz.scheduler_type");
    dataSourceName = configuration.getString("winder.quartz.datasource");

    Scheduler scheduler = null;/*from  ww  w .  j a v a 2s.  c  o m*/
    boolean inMemoryScheduler = false;
    try {
        if ("IN_MEMORY_SCHEDULER".equals(quartzType) || (quartzType == null && dataSourceName == null)) {
            factory.createVolatileScheduler(numThreads);
            scheduler = factory.getScheduler();

            inMemoryScheduler = true;
            if (log.isInfoEnabled()) {
                log.info("Scheduler manager starting IN_MEMORY_SCHEDULER");
            }
        } else {
            ThreadPool threadPool = new SimpleThreadPool(numThreads, Thread.NORM_PRIORITY);
            threadPool.initialize();
            String instanceId = (new SimpleInstanceIdGenerator()).generateInstanceId();

            DBConnectionManager dbMgr = DBConnectionManager.getInstance();

            int poolSize = configuration.getInt("winder.quartz.ds.pool_size", numThreads + 15);

            String jdbcUrl = dataSourceName;
            if ("ds".equals(dataSourceName)) {
                //
                String jdbcDriver = configuration.getString("winder.quartz.ds.driver");
                jdbcUrl = configuration.getString("winder.quartz.ds.url");
                String jdbcUser = configuration.getString("winder.quartz.ds.username");
                String jdbcPassword = configuration.getString("winder.quartz.ds.password");

                String validate = configuration.getString("winder.quartz.ds.validate_sql",
                        "SELECT 1 /* ping */");
                PoolingConnectionProvider pooling = new PoolingConnectionProvider(jdbcDriver, jdbcUrl, jdbcUser,
                        jdbcPassword, poolSize, validate);

                dbMgr.addConnectionProvider(dataSourceName, pooling);
            } else {
                log.warn("Please make sure the data source:" + dataSourceName
                        + " has already been initialized in somewhere else");
            }

            boolean enableQuartz = configuration.getBoolean("winder.quartz.enable", true);

            if (enableQuartz) {
                String tablePrefix = configuration.getString("winder.quartz.ds.table_prefix", "WINDER_");

                reformat(SELECT_JOBS_LIMIT, tablePrefix);
                reformat(SELECT_JOBS_LIMIT_BY_DATE_RANGE, tablePrefix);
                reformat(SELECT_JOBS_LIMIT_LIKE, tablePrefix);
                reformat(SELECT_JOBS_LIMIT_LIKE_BY_DATE_RANGE, tablePrefix);

                int checkInterval = configuration.getInt("winder.quartz.checkin_interval", 7500);
                String clusterName = engine.getClusterName();
                JobStoreTX jdbcJobStore = new WinderJobStoreTx();
                jdbcJobStore.setDataSource(dataSourceName);
                jdbcJobStore.setTablePrefix(tablePrefix);
                jdbcJobStore.setIsClustered(true);
                jdbcJobStore.setClusterCheckinInterval(checkInterval);

                String hostName;
                try {
                    InetAddress inet = InetAddress.getLocalHost();
                    hostName = inet.getHostName();
                } catch (UnknownHostException e) {
                    hostName = "unknownHost";
                }
                jdbcJobStore.setInstanceId(hostName);
                jdbcJobStore.setDriverDelegateClass("org.ebayopensource.winder.quartz.WinderJDBCDelegate");
                jdbcJobStore.setThreadPoolSize(poolSize);

                // To fix the quartz misfire issue
                DefaultThreadExecutor executor = new DefaultThreadExecutor();
                long idleWaitTime = configuration.getLong("winder.quartz.idle_wait_time", 30000L);
                long dbFailureRetryInterval = configuration.getLong("winder.quartz.db_failure_retry_interval",
                        10000L);
                long batchTimeWindow = configuration.getLong("winder.quartz.batch_time_window", 1000L);

                boolean enableQuartzPlugins = configuration.getBoolean("winder.quartz.plugins.enable", false);
                if (enableQuartzPlugins) {
                    Map<String, SchedulerPlugin> schedulerPluginMap = new HashMap<String, SchedulerPlugin>();
                    schedulerPluginMap.put("LoggingTriggerHistoryPlugin", new LoggingTriggerHistoryPlugin());
                    schedulerPluginMap.put("LoggingJobHistoryPlugin", new LoggingJobHistoryPlugin());

                    factory.createScheduler(clusterName, instanceId, threadPool, executor, jdbcJobStore,
                            schedulerPluginMap, null, 0, idleWaitTime, dbFailureRetryInterval, false, null,
                            numThreads, batchTimeWindow);
                } else {
                    factory.createScheduler(clusterName, instanceId, threadPool, executor, jdbcJobStore, null,
                            null, 0, idleWaitTime, dbFailureRetryInterval, false, null, numThreads,
                            batchTimeWindow);
                }
                scheduler = factory.getScheduler(clusterName);
                if (log.isInfoEnabled()) {
                    log.info("Scheduler manager starting with:" + jdbcUrl);
                }
            } else {
                if (log.isInfoEnabled()) {
                    log.info("Scheduler manager disabled!");
                }
            }
        }

        this.quartzScheduler = scheduler;
        this.inMemoryScheduler = inMemoryScheduler;
    } catch (Exception e) {
        if (log.isErrorEnabled()) {
            log.error("Failure initializing quartz", e);
        }
        throw new IllegalStateException("Unable to initialize quartz", e);
    }
}

From source file:org.quartz.impl.DirectSchedulerFactory.java

/**
 * Creates an in memory job store (<code>{@link RAMJobStore}</code>)
 * The thread priority is set to Thread.NORM_PRIORITY
 * /*from  ww w. j a  va2  s  . c  o m*/
 * @param maxThreads
 *          The number of threads in the thread pool
 * @throws SchedulerException
 *           if initialization failed.
 */
public void createVolatileScheduler(int maxThreads) throws SchedulerException {
    SimpleThreadPool threadPool = new SimpleThreadPool(maxThreads, Thread.NORM_PRIORITY);
    threadPool.initialize();
    JobStore jobStore = new RAMJobStore();
    this.createScheduler(threadPool, jobStore);

}