List of usage examples for java.lang Thread setPriority
public final void setPriority(int newPriority)
From source file:de.juwimm.cms.content.modules.ModuleFactoryStandardImpl.java
public void reconfigureModules(Hashtable<String, Element> htModuleDcfNameDcfElement) { Collection coll = this.htModules.values(); Iterator it = coll.iterator(); while (it.hasNext()) { Module module = (Module) it.next(); Thread t = new Thread(Thread.currentThread().getThreadGroup(), new ReconfigureModuleRunnable(module, htModuleDcfNameDcfElement, htInitialContent)); t.setPriority(Thread.NORM_PRIORITY); t.setName("ReconfigureModuleRunnable"); t.start();//from w w w .j av a 2s . c om } }
From source file:org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProviderService.java
private ExecutorService createExecutor() { ThreadPoolExecutor executor = new ThreadPoolExecutor(0, 5, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new ThreadFactory() { private final AtomicInteger counter = new AtomicInteger(); private final Thread.UncaughtExceptionHandler handler = new Thread.UncaughtExceptionHandler() { @Override//from w w w . ja v a2s . com public void uncaughtException(Thread t, Throwable e) { log.warn("Error occurred in asynchronous processing ", e); } }; @Override public Thread newThread(@Nonnull Runnable r) { Thread thread = new Thread(r, createName()); thread.setDaemon(true); thread.setPriority(Thread.MIN_PRIORITY); thread.setUncaughtExceptionHandler(handler); return thread; } private String createName() { return "oak-lucene-" + counter.getAndIncrement(); } }); executor.setKeepAliveTime(1, TimeUnit.MINUTES); executor.allowCoreThreadTimeOut(true); return executor; }
From source file:de.csw.linkgenerator.plugin.lucene.IndexRebuilder.java
public synchronized int startRebuildIndex(XWikiContext context) { if (rebuildInProgress) { LOG.warn("Cannot launch rebuild because a build is in progress"); return LucenePluginApi.REBUILD_IN_PROGRESS; } else {//from w w w.j av a 2 s . c o m this.rebuildInProgress = true; this.context = context; Thread indexRebuilderThread = new Thread(this, "Lucene Index Rebuilder"); // The JVM should be allowed to shutdown while this thread is running indexRebuilderThread.setDaemon(true); // Client requests are more important than indexing indexRebuilderThread.setPriority(3); // Finally, start the rebuild in the background indexRebuilderThread.start(); // Too bad that now we can't tell how many items are there to be indexed... return 0; } }
From source file:feedsplugin.FeedsPlugin.java
void updateFeeds() { Thread thread = new Thread("Update feeds") { @Override/*from www. j ava 2s .c om*/ public void run() { updateFeedsInternal(); } }; thread.setPriority(Thread.MIN_PRIORITY); thread.start(); }
From source file:org.m2x.rssreader.service.FetcherService.java
private int refreshFeeds() { ContentResolver cr = getContentResolver(); final Cursor cursor = cr.query(FeedColumns.CONTENT_URI, FeedColumns.PROJECTION_ID, null, null, null); int nbFeed = cursor.getCount(); ExecutorService executor = Executors.newFixedThreadPool(THREAD_NUMBER, new ThreadFactory() { @Override// ww w. ja va 2 s . c o m public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setPriority(Thread.MIN_PRIORITY); return t; } }); CompletionService<Integer> completionService = new ExecutorCompletionService<Integer>(executor); while (cursor.moveToNext()) { final String feedId = cursor.getString(0); completionService.submit(new Callable<Integer>() { @Override public Integer call() { int result = 0; try { result = refreshFeed(feedId); } catch (Exception ignored) { } return result; } }); } cursor.close(); int globalResult = 0; for (int i = 0; i < nbFeed; i++) { try { Future<Integer> f = completionService.take(); globalResult += f.get(); } catch (Exception ignored) { } } executor.shutdownNow(); // To purge all threads return globalResult; }
From source file:com.opendoorlogistics.core.gis.map.background.MapsforgeTileFactory.java
MapsforgeTileFactory(TileFactoryInfo info, String xmlRenderThemeFilename, MapDataStore mapDatabase, FadeConfig fadeColour) {/*from w w w. ja va 2 s .c o m*/ super(info); this.fadeColour = fadeColour; this.mapDatabase = mapDatabase; zoomLevelConverter = new ZoomLevelConverter(info); databaseRenderer = new DatabaseRenderer(mapDatabase, AwtGraphicFactory.INSTANCE, createDummyTileCacheForMapsforgeLabelPlacementAlgorithm()); renderTheme = getRenderTheme(xmlRenderThemeFilename); model = new DisplayModel(); model.setFixedTileSize(TILE_SIZE); model.setBackgroundColor(backgroundMapColour().getRGB()); // use single thread at the moment as DatabaseRenderer is probably single threaded service = Executors.newFixedThreadPool(1, new ThreadFactory() { private int count = 0; @Override public Thread newThread(Runnable r) { Thread t = new Thread(r, "mapsforge-tile-pool-" + count++); t.setPriority(Thread.MIN_PRIORITY); t.setDaemon(true); return t; } }); }
From source file:com.nesscomputing.syslog4j.impl.AbstractSyslog.java
public Thread createWriterThread(AbstractSyslogWriter syslogWriter) { Thread newWriterThread = new Thread(syslogWriter); newWriterThread.setName("SyslogWriter: " + getProtocol()); newWriterThread.setDaemon(syslogConfig.isUseDaemonThread()); if (syslogConfig.getThreadPriority() > -1) { newWriterThread.setPriority(syslogConfig.getThreadPriority()); }// ww w . ja va2 s .c om syslogWriter.setThread(newWriterThread); newWriterThread.start(); return newWriterThread; }
From source file:org.apache.hyracks.control.nc.NodeControllerService.java
@Override public void start() throws Exception { LOGGER.log(Level.INFO, "Starting NodeControllerService"); ipc.start();//from w ww. ja v a 2 s. c o m netManager.start(); startApplication(); init(); datasetNetworkManager.start(); if (messagingNetManager != null) { messagingNetManager.start(); } IIPCHandle ccIPCHandle = ipc.getHandle(new InetSocketAddress(ncConfig.ccHost, ncConfig.ccPort), ncConfig.retries); this.ccs = new ClusterControllerRemoteProxy(ccIPCHandle); HeartbeatSchema.GarbageCollectorInfo[] gcInfos = new HeartbeatSchema.GarbageCollectorInfo[gcMXBeans.size()]; for (int i = 0; i < gcInfos.length; ++i) { gcInfos[i] = new HeartbeatSchema.GarbageCollectorInfo(gcMXBeans.get(i).getName()); } HeartbeatSchema hbSchema = new HeartbeatSchema(gcInfos); // Use "public" versions of network addresses and ports NetworkAddress datasetAddress = datasetNetworkManager.getPublicNetworkAddress(); NetworkAddress netAddress = netManager.getPublicNetworkAddress(); NetworkAddress meesagingPort = messagingNetManager != null ? messagingNetManager.getPublicNetworkAddress() : null; ccs.registerNode(new NodeRegistration(ipc.getSocketAddress(), id, ncConfig, netAddress, datasetAddress, osMXBean.getName(), osMXBean.getArch(), osMXBean.getVersion(), osMXBean.getAvailableProcessors(), runtimeMXBean.getVmName(), runtimeMXBean.getVmVersion(), runtimeMXBean.getVmVendor(), runtimeMXBean.getClassPath(), runtimeMXBean.getLibraryPath(), runtimeMXBean.getBootClassPath(), runtimeMXBean.getInputArguments(), runtimeMXBean.getSystemProperties(), hbSchema, meesagingPort, PidHelper.getPid())); synchronized (this) { while (registrationPending) { wait(); } } if (registrationException != null) { throw registrationException; } appCtx.setDistributedState(nodeParameters.getDistributedState()); workQueue.start(); heartbeatTask = new HeartbeatTask(ccs); // Use reflection to set the priority of the timer thread. Field threadField = timer.getClass().getDeclaredField("thread"); threadField.setAccessible(true); Thread timerThread = (Thread) threadField.get(timer); // The internal timer thread of the Timer object. timerThread.setPriority(Thread.MAX_PRIORITY); // Schedule heartbeat generator. timer.schedule(heartbeatTask, 0, nodeParameters.getHeartbeatPeriod()); if (nodeParameters.getProfileDumpPeriod() > 0) { // Schedule profile dump generator. timer.schedule(new ProfileDumpTask(ccs), 0, nodeParameters.getProfileDumpPeriod()); } LOGGER.log(Level.INFO, "Started NodeControllerService"); if (ncAppEntryPoint != null) { ncAppEntryPoint.notifyStartupComplete(); } }
From source file:org.jumpmind.symmetric.service.impl.PushService.java
public void start() { nodeChannelExtractForPushWorker = (ThreadPoolExecutor) Executors.newCachedThreadPool(new ThreadFactory() { final AtomicInteger threadNumber = new AtomicInteger(1); final String namePrefix = parameterService.getEngineName().toLowerCase() + "-extract-for-push-"; public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName(namePrefix + threadNumber.getAndIncrement()); t.setDaemon(false);/*from ww w . ja v a2 s . com*/ if (t.getPriority() != Thread.NORM_PRIORITY) { t.setPriority(Thread.NORM_PRIORITY); } return t; } }); nodeChannelTransportForPushWorker = (ThreadPoolExecutor) Executors.newCachedThreadPool(new ThreadFactory() { final AtomicInteger threadNumber = new AtomicInteger(1); final String namePrefix = parameterService.getEngineName().toLowerCase() + "-push-"; public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName(namePrefix + threadNumber.getAndIncrement()); t.setDaemon(false); if (t.getPriority() != Thread.NORM_PRIORITY) { t.setPriority(Thread.NORM_PRIORITY); } return t; } }); }
From source file:org.apache.cocoon.components.store.impl.StoreJanitorImpl.java
private void doStart() throws Exception { this.doRun = true; Thread checker = new Thread(this); if (getLogger().isDebugEnabled()) { getLogger().debug("Intializing checker thread"); }//from w ww .j av a 2 s. c om checker.setPriority(getPriority()); checker.setDaemon(true); checker.setName("checker"); checker.start(); }