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.batoo.jpa.benchmark.BenchmarkTest.java

private ThreadPoolExecutor createExecutor(BlockingQueue<Runnable> workQueue) {
    final AtomicInteger nextThreadNo = new AtomicInteger(0);

    final ThreadPoolExecutor executor = new ThreadPoolExecutor(//
            BenchmarkTest.THREAD_COUNT, BenchmarkTest.THREAD_COUNT, // min max threads
            0L, TimeUnit.MILLISECONDS, // the keep alive time - hold it forever
            workQueue, new ThreadFactory() {

                @Override//from   www. j  a v a2  s.  co m
                public Thread newThread(Runnable r) {
                    final Thread t = new Thread(r);
                    t.setDaemon(true);
                    t.setPriority(Thread.NORM_PRIORITY);
                    t.setName("Benchmark-" + nextThreadNo.get());

                    BenchmarkTest.this.threadIds[nextThreadNo.getAndIncrement()] = t.getId();

                    return t;
                }
            });

    executor.prestartAllCoreThreads();

    return executor;
}

From source file:org.alfresco.solr.client.SOLRAPIClientTest.java

@Override
public void setUp() throws Exception {
    if (client == null) {
        TenantService tenantService = new SingleTServiceImpl();

        dictionaryDAO = new DictionaryDAOImpl();
        NamespaceDAO namespaceDAO = dictionaryDAO;
        dictionaryDAO.setTenantService(tenantService);

        CompiledModelsCache compiledModelsCache = new CompiledModelsCache();
        compiledModelsCache.setDictionaryDAO(dictionaryDAO);
        compiledModelsCache.setTenantService(tenantService);
        compiledModelsCache.setRegistry(new DefaultAsynchronouslyRefreshedCacheRegistry());
        TraceableThreadFactory threadFactory = new TraceableThreadFactory();
        threadFactory.setThreadDaemon(true);
        threadFactory.setThreadPriority(Thread.NORM_PRIORITY);

        ThreadPoolExecutor threadPoolExecutor = new DynamicallySizedThreadPoolExecutor(20, 20, 90,
                TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), threadFactory,
                new ThreadPoolExecutor.CallerRunsPolicy());
        compiledModelsCache.setThreadPoolExecutor(threadPoolExecutor);
        dictionaryDAO.setDictionaryRegistryCache(compiledModelsCache);
        // TODO: use config ....
        dictionaryDAO.setDefaultAnalyserResourceBundleName("alfresco/model/dataTypeAnalyzers");
        dictionaryDAO.setResourceClassLoader(getResourceClassLoader());
        dictionaryDAO.init();//from   w ww  .  jav a2  s  .  co m

        DictionaryComponent dictionaryComponent = new DictionaryComponent();
        dictionaryComponent.setDictionaryDAO(dictionaryDAO);
        dictionaryComponent.setMessageLookup(new StaticMessageLookup());

        // cmis dictionary
        CMISMapping cmisMapping = new CMISMapping();
        cmisMapping.setCmisVersion(CmisVersion.CMIS_1_0);
        DictionaryNamespaceComponent namespaceService = new DictionaryNamespaceComponent();
        namespaceService.setNamespaceDAO(namespaceDAO);
        cmisMapping.setNamespaceService(namespaceService);
        cmisMapping.setDictionaryService(dictionaryComponent);
        cmisMapping.afterPropertiesSet();

        cmisDictionaryService = new CMISStrictDictionaryService();
        cmisDictionaryService.setCmisMapping(cmisMapping);
        cmisDictionaryService.setDictionaryService(dictionaryComponent);
        cmisDictionaryService.setDictionaryDAO(dictionaryDAO);
        cmisDictionaryService.setSingletonCache(new MemoryCache<String, CMISDictionaryRegistry>());
        cmisDictionaryService.setTenantService(tenantService);
        cmisDictionaryService.init();

        RuntimePropertyLuceneBuilderMapping luceneBuilderMapping = new RuntimePropertyLuceneBuilderMapping();
        luceneBuilderMapping.setDictionaryService(dictionaryComponent);
        luceneBuilderMapping.setCmisDictionaryService(cmisDictionaryService);
        cmisDictionaryService.setPropertyLuceneBuilderMapping(luceneBuilderMapping);

        luceneBuilderMapping.afterPropertiesSet();

        // Load the key store from the classpath
        ClasspathKeyResourceLoader keyResourceLoader = new ClasspathKeyResourceLoader();
        client = new SOLRAPIClient(getRepoClient(keyResourceLoader), dictionaryComponent, dictionaryDAO);
        trackModels();
    }
}

From source file:net.pms.util.BasicThreadFactory.java

/**
 * Creates a new {@link BasicThreadFactory} using the given arguments and
 * priority {@link Thread#NORM_PRIORITY}.
 * <p>//from   w  ww  .jav  a 2s  . com
 * The {@link Thread} names generated by the new {@link BasicThreadFactory}
 * is created by calling {@link String#format} with {@code namePattern} as
 * the "format" and pool- and thread number as arguments. The formatting
 * rules are those of {@link java.util.Formatter}.
 * <p>
 * No more than two variables of type {@code %d} or {@code %s} is allowed in
 * {@code namePattern}, and they will be substituted as follows:
 * <ul>
 * <li>No variables: All {@link Thread} names generated by this
 * {@link ThreadFactory} will be equal to {@code namePattern}.</li>
 * <li>One variable: Only thread number will be used, pool number isn't
 * used.</li>
 * <li>Two variables: Pool number will be used for the first variable in
 * {@code namePattern}, thread number for the second.
 * </ul>
 *
 * @param namePattern The {@link java.util.Formatter} formatted
 *            {@link String} from which to generate {@link Thread} names.
 * @param group The {@link ThreadGroup}.
 */
public BasicThreadFactory(String namePattern, ThreadGroup group) {
    this(namePattern, Thread.NORM_PRIORITY, group);
}

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

public Thread newThread(Runnable r) {
    String prefix = "polymap-worker-";
    Thread t = new Thread(r, prefix + threadNumber.getAndIncrement());
    t.setDaemon(false);/*from w w  w . ja  v a2 s. c  o  m*/
    t.setPriority(Thread.NORM_PRIORITY - 1);
    return t;
}

From source file:yoda.threads.ResponderExecutionHandler.java

/**
 * Return the thread priority.//ww w. ja v  a 2s. com
 * 
 * If the property is not there then normal priority will be used.
 * 
 * @param value
 * @return the priority
 * @throws IllegalArgumentException if the value is invalid.
 * @since 1.0
 */
private int parseThreadPriority(String value) {
    // It has not been set, so set it at 5
    if (StringUtils.isBlank(value)) {
        return Thread.NORM_PRIORITY;
    }

    try {
        int priority = Integer.parseInt(value);
        if (priority > Thread.MAX_PRIORITY || priority < Thread.MIN_PRIORITY) {
            throw new IllegalArgumentException(THREAD_PRIORITY_KEY);
        }

        return priority;
    } catch (NumberFormatException numberFormatException) {
        throw new IllegalArgumentException(THREAD_PRIORITY_KEY);
    }
}

From source file:com.souvenir.android.DrawerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_drawer);

    STrip strip = new STrip("uncategorized");
    strip.setDirty(true);//from  w ww . j  a v  a2  s  . c  om
    strip.insert(this);

    if (!ImageLoader.getInstance().isInited()) {
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this.getApplicationContext())
                .threadPriority(Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory()
                /* .enableLogging() */.build();
        ImageLoader.getInstance().init(config);
    }
    mTitle = mDrawerTitle = getTitle();
    mDrawerTitles = getResources().getStringArray(R.array.drawer_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new aa(this, R.layout.drawer_list_item, mDrawerTitles));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    int titleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
    TextView yourTextView = (TextView) findViewById(titleId);
    yourTextView.setTextColor(getResources().getColor(android.R.color.white));

    prefs = getSharedPreferences(getPackageName(), Context.MODE_PRIVATE);
    if (prefs.contains("autosync")) {
        autosync = prefs.getBoolean("autosync", false);
    }

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            // String curTitle = (String) getSupportActionBar().getTitle();
            // if (curTitle.toString().contains(":"))
            // {
            // setTitle(curTitle);
            // }
            // else
            // {
            //
            // getSupportActionBar().setTitle(mTitle);
            // }
            getSupportActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        selectItem(COMPLETED_POSITION);
    }
}

From source file:is.landsbokasafn.crawler.rss.RssCrawlController.java

/**
 * Start the dedicated thread with an independent view of the frontier's
 * state. /*  w ww.ja  v a  2s.  co  m*/
 */
protected void startManagerThread() {
    managerThread = new Thread(this + ".managerThread") {
        public void run() {
            log.fine("Starting manager thread");
            RssCrawlController.this.controlTasks();
        }
    };
    managerThread.setPriority(Thread.NORM_PRIORITY + 1);
    managerThread.start();
}

From source file:com.bigdata.dastor.db.HintedHandOffManager.java

public HintedHandOffManager() {
    int hhPriority = System.getProperty("bigdata.dastor.deputytransfer.priority") == null ? Thread.NORM_PRIORITY
            : Integer.parseInt(System.getProperty("bigdata.dastor.deputytransfer.priority"));
    executor_ = new JMXEnabledThreadPoolExecutor("HINTED-HANDOFF-POOL", hhPriority);
}

From source file:org.mariotaku.twidere.util.dagger.ApplicationModule.java

@Provides
@Singleton/*from   w  w w .  jav  a2 s.  c o  m*/
public ImageLoader imageLoader(SharedPreferencesWrapper preferences, MediaDownloader downloader) {
    final ImageLoader loader = ImageLoader.getInstance();
    final ImageLoaderConfiguration.Builder cb = new ImageLoaderConfiguration.Builder(application);
    cb.threadPriority(Thread.NORM_PRIORITY - 2);
    cb.denyCacheImageMultipleSizesInMemory();
    cb.tasksProcessingOrder(QueueProcessingType.LIFO);
    // cb.memoryCache(new ImageMemoryCache(40));
    cb.diskCache(createDiskCache("images", preferences));
    cb.imageDownloader(new TwidereImageDownloader(application, downloader));
    L.writeDebugLogs(BuildConfig.DEBUG);
    loader.init(cb.build());
    return loader;
}

From source file:org.eclipse.scanning.event.SubscriberImpl.java

private void schedule(DiseminateEvent event) {
    if (isSynchronous()) {
        if (queue != null)
            queue.add(event);//w  w w.j a  v  a2 s .c o  m
    } else {
        if (event == DiseminateEvent.STOP)
            return;
        // TODO FIXME Might not be right...
        final Thread thread = new Thread("Execute event " + getTopicName()) {
            public void run() {
                diseminate(event); // Use this JMS thread directly to do work.
            }
        };
        thread.setDaemon(true);
        thread.setPriority(Thread.NORM_PRIORITY + 1);
        thread.start();
    }
}