List of usage examples for java.lang Thread NORM_PRIORITY
int NORM_PRIORITY
To view the source code for java.lang Thread NORM_PRIORITY.
Click Source Link
From source file:phex.download.swarming.SwarmingManager.java
public SwarmingManager(Peer peer, SharedFilesService sharedFilesService) { if (peer == null) { throw new NullPointerException("Servent is null."); }//from w w w . j ava 2 s.c o m // if ( eventService == null ) // { // throw new NullPointerException( "PhexEventService is null." ); // } if (sharedFilesService == null) { throw new NullPointerException("SharedFilesService is null."); } this.peer = peer; this.sharedFilesService = sharedFilesService; downloadListChangedSinceSave = false; isManagerShutingDown = false; workerList = new ArrayList<SWDownloadWorker>(5); downloadList = new ArrayList<SWDownloadFile>(5); urnToDownloadMap = new HashMap<URN, SWDownloadFile>(); ipDownloadCounter = new AddressCounter(peer.downloadPrefs.MaxDownloadsPerIP.get().intValue(), false); dataWriter = new DownloadDataWriter(this); downloadVerifyRunner = new RunnerQueueWorker(Thread.NORM_PRIORITY - 1); downloadWriteBufferTracker = new BufferVolumeTracker( peer.downloadPrefs.MaxTotalDownloadWriteBuffer.get().intValue(), dataWriter); if (peer.downloadPrefs.CandidateLogBufferSize.get().intValue() > 0) { candidateLogBuffer = new LogBuffer(peer.downloadPrefs.CandidateLogBufferSize.get().intValue()); } }
From source file:org.apache.hyracks.control.nc.NodeControllerService.java
public NodeControllerService(NCConfig ncConfig) throws Exception { this.ncConfig = ncConfig; id = ncConfig.nodeId;/*from w w w . ja v a 2 s .c o m*/ ipc = new IPCSystem(new InetSocketAddress(ncConfig.clusterNetIPAddress, ncConfig.clusterNetPort), new NodeControllerIPCI(this), new CCNCFunctions.SerializerDeserializer()); ioManager = new IOManager(getDevices(ncConfig.ioDevices)); if (id == null) { throw new Exception("id not set"); } partitionManager = new PartitionManager(this); netManager = new NetworkManager(ncConfig.dataIPAddress, ncConfig.dataPort, partitionManager, ncConfig.nNetThreads, ncConfig.nNetBuffers, ncConfig.dataPublicIPAddress, ncConfig.dataPublicPort, FullFrameChannelInterfaceFactory.INSTANCE); lccm = new LifeCycleComponentManager(); workQueue = new WorkQueue(id, Thread.NORM_PRIORITY); // Reserves MAX_PRIORITY of the heartbeat thread. jobletMap = new Hashtable<>(); timer = new Timer(true); serverCtx = new ServerContext(ServerContext.ServerType.NODE_CONTROLLER, new File(new File(NodeControllerService.class.getName()), id)); memoryMXBean = ManagementFactory.getMemoryMXBean(); gcMXBeans = ManagementFactory.getGarbageCollectorMXBeans(); threadMXBean = ManagementFactory.getThreadMXBean(); runtimeMXBean = ManagementFactory.getRuntimeMXBean(); osMXBean = ManagementFactory.getOperatingSystemMXBean(); registrationPending = true; getNodeControllerInfosAcceptor = new MutableObject<>(); memoryManager = new MemoryManager( (long) (memoryMXBean.getHeapMemoryUsage().getMax() * MEMORY_FUDGE_FACTOR)); ioCounter = new IOCounterFactory().getIOCounter(); }
From source file:com.alibaba.jstorm.daemon.worker.Worker.java
public WorkerShutdown execute() throws Exception { List<AsyncLoopThread> threads = new ArrayList<AsyncLoopThread>(); startDispatchThread();/* w w w . jav a 2s .c om*/ // create client before create task // so create client connection before create task // refresh connection RefreshConnections refreshConn = makeRefreshConnections(); AsyncLoopThread refreshconn = new AsyncLoopThread(refreshConn, false, Thread.MIN_PRIORITY, true); threads.add(refreshconn); // refresh ZK active status RefreshActive refreshZkActive = new RefreshActive(workerData); AsyncLoopThread refreshzk = new AsyncLoopThread(refreshZkActive, false, Thread.MIN_PRIORITY, true); threads.add(refreshzk); // Sync heartbeat to Apsara Container AsyncLoopThread syncContainerHbThread = SyncContainerHb.mkWorkerInstance(workerData.getStormConf()); if (syncContainerHbThread != null) { threads.add(syncContainerHbThread); } JStormMetricsReporter metricReporter = new JStormMetricsReporter(workerData); metricReporter.init(); workerData.setMetricsReporter(metricReporter); // refresh hearbeat to Local dir RunnableCallback heartbeat_fn = new WorkerHeartbeatRunable(workerData); AsyncLoopThread hb = new AsyncLoopThread(heartbeat_fn, false, null, Thread.NORM_PRIORITY, true); threads.add(hb); // shutdown task callbacks List<TaskShutdownDameon> shutdowntasks = createTasks(); workerData.setShutdownTasks(shutdowntasks); return new WorkerShutdown(workerData, threads); }
From source file:com.espertech.esper.core.thread.ThreadingServiceImpl.java
private ThreadPoolExecutor getThreadPool(String engineURI, String name, BlockingQueue<Runnable> queue, int numThreads) { if (log.isInfoEnabled()) { log.info("Starting pool " + name + " with " + numThreads + " threads"); }/*from w w w . j ava2 s . co m*/ if (engineURI == null) { engineURI = "default"; } String threadGroupName = "com.espertech.esper." + engineURI + "-" + name; ThreadGroup threadGroup = new ThreadGroup(threadGroupName); ThreadPoolExecutor pool = new ThreadPoolExecutor(numThreads, numThreads, 1, TimeUnit.SECONDS, queue, new EngineThreadFactory(engineURI, name, threadGroup, Thread.NORM_PRIORITY)); pool.prestartAllCoreThreads(); return pool; }
From source file:com.android.quake.llvm.DownloaderActivity.java
private void startDownloadThread() { mSuppressErrorMessages = false;//from ww w . jav a2 s. co m mProgress.setText(""); mTimeRemaining.setText(""); mDownloadThread = new Thread(new Downloader(), "Downloader"); mDownloadThread.setPriority(Thread.NORM_PRIORITY - 1); mDownloadThread.start(); }
From source file:org.parosproxy.paros.core.proxy.ProxyThread.java
ProxyThread(ProxyServer server, Socket socket) { parentServer = server;/* w ww .ja va 2 s. c o m*/ proxyParam = parentServer.getProxyParam(); connectionParam = parentServer.getConnectionParam(); inSocket = socket; try { inSocket.setTcpNoDelay(true); // ZAP: Set timeout inSocket.setSoTimeout(connectionParam.getTimeoutInSecs() * 1000); } catch (SocketException e) { // ZAP: Log exceptions log.warn(e.getMessage(), e); } thread = new Thread(this, "ZAP-ProxyThread-" + id++); // ZAP: Set the name of the thread. thread.setDaemon(true); thread.setPriority(Thread.NORM_PRIORITY - 1); }
From source file:org.eclipse.scanning.event.SubscriberImpl.java
private void createDiseminateThread() { if (!isSynchronous()) return; // If asynch we do not run events in order and wait until they return. if (queue != null) return;/*from w w w . j ava 2s. c o m*/ queue = new LinkedBlockingQueue<>(); // Small, if they do work and things back-up, exceptions will occur. final Thread despachter = new Thread(new Runnable() { public void run() { while (isConnected()) { try { DiseminateEvent event = queue.take(); if (event == DiseminateEvent.STOP) return; diseminate(event); } catch (RuntimeException e) { e.printStackTrace(); logger.error("RuntimeException occured despatching event", e); continue; } catch (Exception e) { e.printStackTrace(); logger.error("Stopping event despatch thread ", e); return; } } System.out.println(Thread.currentThread().getName() + " disconnecting events."); } }, "Submitter despatch thread " + getSubmitQueueName()); despachter.setDaemon(true); despachter.setPriority(Thread.NORM_PRIORITY + 1); despachter.start(); }
From source file:com.ery.estorm.util.Threads.java
/** * Get a named {@link ThreadFactory} that just builds daemon threads. * /*from w ww . java 2s . c o m*/ * @param prefix * name prefix for all threads created from the factory * @param handler * unhandles exception handler to set for all threads * @return a thread factory that creates named, daemon threads with the supplied exception handler and normal priority */ public static ThreadFactory newDaemonThreadFactory(final String prefix, final UncaughtExceptionHandler handler) { final ThreadFactory namedFactory = getNamedThreadFactory(prefix); return new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = namedFactory.newThread(r); if (handler != null) { t.setUncaughtExceptionHandler(handler); } if (!t.isDaemon()) { t.setDaemon(true); } if (t.getPriority() != Thread.NORM_PRIORITY) { t.setPriority(Thread.NORM_PRIORITY); } return t; } }; }
From source file:com.baidu.asynchttpclient.AsyncHttpClient.java
/** * Creates a new AsyncHttpClient./*ww w . j av a2 s . c o m*/ */ public AsyncHttpClient() { BasicHttpParams httpParams = new BasicHttpParams(); ConnManagerParams.setTimeout(httpParams, socketTimeout); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(maxConnections)); ConnManagerParams.setMaxTotalConnections(httpParams, DEFAULT_MAX_CONNECTIONS); HttpConnectionParams.setSoTimeout(httpParams, socketTimeout); HttpConnectionParams.setConnectionTimeout(httpParams, socketTimeout); HttpConnectionParams.setTcpNoDelay(httpParams, true); HttpConnectionParams.setSocketBufferSize(httpParams, DEFAULT_SOCKET_BUFFER_SIZE); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setUserAgent(httpParams, String.format("android-async-http/%s (http://loopj.com/android-async-http)", VERSION)); HttpProtocolParams.setUseExpectContinue(httpParams, false); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); // schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry); httpContext = new SyncBasicHttpContext(new BasicHttpContext()); httpClient = new DefaultHttpClient(cm, httpParams); httpClient.addRequestInterceptor(new HttpRequestInterceptor() { public void process(HttpRequest request, HttpContext context) { if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) { request.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP); } for (String header : clientHeaderMap.keySet()) { request.addHeader(header, clientHeaderMap.get(header)); } } }); httpClient.addResponseInterceptor(new HttpResponseInterceptor() { public void process(HttpResponse response, HttpContext context) { final HttpEntity entity = response.getEntity(); final Header encoding = entity.getContentEncoding(); if (encoding != null) { for (HeaderElement element : encoding.getElements()) { if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) { response.setEntity(new InflatingEntity(response.getEntity())); break; } } } } }); httpClient.setHttpRequestRetryHandler(new RetryHandler(DEFAULT_MAX_RETRIES)); threadPool = (ThreadPoolExecutor) Executors.newCachedThreadPool(new ThreadFactory() { private final AtomicInteger mCount = new AtomicInteger(1); public Thread newThread(Runnable r) { Thread t = new Thread(r, "AsyncHttpClient #" + mCount.getAndIncrement()); if (t.isDaemon()) t.setDaemon(false); if (t.getPriority() != (Thread.NORM_PRIORITY - 1)) t.setPriority((Thread.NORM_PRIORITY - 1)); return t; } }); requestMap = new WeakHashMap<Context, List<WeakReference<Future<?>>>>(); clientHeaderMap = new HashMap<String, String>(); }
From source file:com.alibaba.jstorm.daemon.worker.hearbeat.SyncContainerHb.java
public static AsyncLoopThread mkInstance(String containerHbDir, String hbDir, int timeout, int frequence) { SyncContainerHb syncContainerHbThread = new SyncContainerHb(); syncContainerHbThread.setReadDir(containerHbDir); syncContainerHbThread.setWriteDir(hbDir); syncContainerHbThread.setTimeoutSeconds(timeout); syncContainerHbThread.setFrequence(frequence); StringBuilder sb = new StringBuilder(); sb.append("Run process under Apsara/Yarn container"); sb.append("ContainerDir:").append(containerHbDir); sb.append("MyDir:").append(hbDir); sb.append(", timeout:").append(timeout); sb.append(",frequence:").append(frequence); LOG.info(sb.toString());/*from w w w. j a v a 2 s. c om*/ AsyncLoopThread thread = new AsyncLoopThread(syncContainerHbThread, true, Thread.NORM_PRIORITY, true); return thread; }