List of usage examples for java.lang Thread setName
public final synchronized void setName(String name)
From source file:com.ttech.cordovabuild.infrastructure.queue.BuiltQueuePollerFactory.java
@PostConstruct void buildQueuePollers() { LOGGER.info("built.types value {} and builtQueue prefix {}", builtTypes, builtQueuePrefix); String[] split = builtTypes.split(","); for (String splitVal : split) { BuiltType builtType = BuiltType.valueOf(splitVal); IQueue<Long> queue = hazelcastInstance.getQueue(builtQueuePrefix + "." + builtType.getPlatformString()); Thread pollerThread = new Thread( (new QueuePoller(queueListener, applicationService, builtType, queue))); pollerThread.setName(builtType.getPlatformString() + "BuiltPoller"); pollerThread.start();//from w ww . j a va2 s.c o m } }
From source file:org.wso2.carbon.throttle.core.ThrottleReplicator.java
public ThrottleReplicator() { String replicatorThreads = System.getProperty("throttling.pool.size"); if (replicatorThreads != null) { replicatorPoolSize = Integer.parseInt(replicatorThreads); }//from w ww . ja v a 2 s. c o m log.debug("Replicator pool size set to " + replicatorPoolSize); ScheduledExecutorService executor = Executors.newScheduledThreadPool(replicatorPoolSize, new ThreadFactory() { public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName("Throttle Replicator - " + replicatorCount++); return t; } }); String throttleFrequency = System.getProperty("throttling.replication.frequency"); if (throttleFrequency == null) { throttleFrequency = "50"; } log.debug("Throttling Frequency set to " + throttleFrequency); String maxKeysToReplicate = System.getProperty("throttling.keys.to.replicate"); if (maxKeysToReplicate != null) { keysToReplicate = Integer.parseInt(maxKeysToReplicate); } log.debug("Max keys to Replicate " + keysToReplicate); for (int i = 0; i < replicatorPoolSize; i++) { executor.scheduleAtFixedRate(new ReplicatorTask(), Integer.parseInt(throttleFrequency), Integer.parseInt(throttleFrequency), TimeUnit.MILLISECONDS); } }
From source file:com.taobao.pushit.server.listener.ConnectionNumberListener.java
public ConnectionNumberListener(int connThreshold, int ipCountThreshold, int ipCheckTaskInterval) { this.connThreshold = connThreshold; this.ipCountThreshold = ipCountThreshold; this.ipCheckTaskInterval = ipCheckTaskInterval; this.scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName("connection num control thread"); t.setDaemon(true);//from www. j a v a 2 s . co m return t; } }); this.scheduler.scheduleAtFixedRate(new Runnable() { public void run() { int ipCount = ConnectionNumberListener.this.connectionIpNumMap.size(); if (ipCount >= ConnectionNumberListener.this.ipCountThreshold) { log.warn("IP, IP, IP=" + ipCount + ", =" + ConnectionNumberListener.this.ipCountThreshold); isOverflow = true; } else { isOverflow = false; } } }, this.ipCheckTaskInterval, this.ipCheckTaskInterval, TimeUnit.SECONDS); }
From source file:org.apache.synapse.commons.throttle.core.ThrottleReplicator.java
public ThrottleReplicator() { String replicatorThreads = System.getProperty("throttling.pool.size"); if (replicatorThreads != null) { replicatorPoolSize = Integer.parseInt(replicatorThreads); }/*ww w. j ava2 s. c o m*/ log.debug("Replicator pool size set to " + replicatorPoolSize); ScheduledExecutorService executor = Executors.newScheduledThreadPool(replicatorPoolSize, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName("Throttle Replicator - " + replicatorCount++); return t; } }); String throttleFrequency = System.getProperty("throttling.replication.frequency"); if (throttleFrequency == null) { throttleFrequency = "50"; } log.debug("Throttling Frequency set to " + throttleFrequency); String maxKeysToReplicate = System.getProperty("throttling.keys.to.replicate"); if (maxKeysToReplicate != null) { keysToReplicate = Integer.parseInt(maxKeysToReplicate); } log.debug("Max keys to Replicate " + keysToReplicate); for (int i = 0; i < replicatorPoolSize; i++) { executor.scheduleAtFixedRate(new ReplicatorTask(), Integer.parseInt(throttleFrequency), Integer.parseInt(throttleFrequency), TimeUnit.MILLISECONDS); } }
From source file:SwingWorker.java
/** * returns workersExecutorService./* ww w .ja v a 2s .c om*/ * * returns the service stored in the appContext or creates it if * necessary. If the last one it triggers autoShutdown thread to * get started. * * @return ExecutorService for the {@code SwingWorkers} * @see #startAutoShutdownThread */ private static synchronized ExecutorService getWorkersExecutorService() { if (executorService == null) { //this creates non-daemon threads. ThreadFactory threadFactory = new ThreadFactory() { final ThreadFactory defaultFactory = Executors.defaultThreadFactory(); public Thread newThread(final Runnable r) { Thread thread = defaultFactory.newThread(r); thread.setName("SwingWorker-" + thread.getName()); return thread; } }; /* * We want a to have no more than MAX_WORKER_THREADS * running threads. * * We want a worker thread to wait no longer than 1 second * for new tasks before terminating. */ executorService = new ThreadPoolExecutor(0, MAX_WORKER_THREADS, 1L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), threadFactory) { private final ReentrantLock pauseLock = new ReentrantLock(); private final Condition unpaused = pauseLock.newCondition(); private boolean isPaused = false; private final ReentrantLock executeLock = new ReentrantLock(); @Override public void execute(Runnable command) { /* * ThreadPoolExecutor first tries to run task * in a corePool. If all threads are busy it * tries to add task to the waiting queue. If it * fails it run task in maximumPool. * * We want corePool to be 0 and * maximumPool to be MAX_WORKER_THREADS * We need to change the order of the execution. * First try corePool then try maximumPool * pool and only then store to the waiting * queue. We can not do that because we would * need access to the private methods. * * Instead we enlarge corePool to * MAX_WORKER_THREADS before the execution and * shrink it back to 0 after. * It does pretty much what we need. * * While we changing the corePoolSize we need * to stop running worker threads from accepting new * tasks. */ //we need atomicity for the execute method. executeLock.lock(); try { pauseLock.lock(); try { isPaused = true; } finally { pauseLock.unlock(); } setCorePoolSize(MAX_WORKER_THREADS); super.execute(command); setCorePoolSize(0); pauseLock.lock(); try { isPaused = false; unpaused.signalAll(); } finally { pauseLock.unlock(); } } finally { executeLock.unlock(); } } @Override protected void afterExecute(Runnable r, Throwable t) { super.afterExecute(r, t); pauseLock.lock(); try { while (isPaused) { unpaused.await(); } } catch (InterruptedException ignore) { } finally { pauseLock.unlock(); } } }; } return executorService; }
From source file:com.github.vatbub.awsvpnlauncher.Main.java
/** * Connects to the specified instance using ssh. Output will be sent to System.out, input will be taken from System.in * * @param instanceID The id of the instance to connect to *//*from w w w . jav a2s.c om*/ private static void ssh(String instanceID) { try { File privateKey = new File(prefs.getPreference(Property.privateKeyFile)); DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest(); List<String> instanceId = new ArrayList<>(1); instanceId.add(instanceID); describeInstancesRequest.setInstanceIds(instanceId); DescribeInstancesResult describeInstancesResult = client.describeInstances(describeInstancesRequest); Instance instance = describeInstancesResult.getReservations().get(0).getInstances().get(0); String sshIp = instance.getPublicDnsName(); // SSH config FOKLogger.info(Main.class.getName(), "Configuring SSH..."); Properties sshConfig = new Properties(); sshConfig.put("StrictHostKeyChecking", "no"); JSch jsch = new JSch(); jsch.addIdentity(privateKey.getAbsolutePath()); FOKLogger.info(Main.class.getName(), "Connecting using ssh to " + sshUsername + "@" + sshIp); session = jsch.getSession(sshUsername, sshIp, 22); session.setConfig(sshConfig); try { session.connect(); } catch (Exception e) { FOKLogger.log(Main.class.getName(), Level.SEVERE, "Could not connect to the instance due to an exception", e); } // Connected FOKLogger.info(Main.class.getName(), "Connection established, connected to " + sshUsername + "@" + sshIp); Channel channel = session.openChannel("shell"); if (posix.isatty(FileDescriptor.out)) { FOKLogger.info(Main.class.getName(), "Connected to a tty, disabling colors..."); // Disable colors ((ChannelShell) channel).setPtyType("vt102"); } channel.setInputStream(copyAndFilterInputStream()); channel.setOutputStream(new MyPrintStream()); channel.connect(); NullOutputStream nullOutputStream = new NullOutputStream(); Thread watchForSSHDisconnectThread = new Thread(() -> { while (channel.isConnected()) { nullOutputStream.write(0); } // disconnected System.exit(0); }); watchForSSHDisconnectThread.setName("watchForSSHDisconnectThread"); watchForSSHDisconnectThread.start(); } catch (JSchException | IOException e) { FOKLogger.log(Main.class.getName(), Level.SEVERE, "An error occurred", e); } }
From source file:org.xenmaster.monitoring.MonitoringAgent.java
protected final void setUpEngine() { engine = Executors.newCachedThreadPool(new ThreadFactory() { @Override//from w w w . j a v a 2 s. co m public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName("Monitoring engine " + r.getClass().getSimpleName()); return t; } }); SequenceBarrier collectorBarrier = ringBuffer.newBarrier(); BatchEventProcessor<Record> cr = new BatchEventProcessor<>(ringBuffer, collectorBarrier, collector); SequenceBarrier correlatorBarrier = ringBuffer.newBarrier(cr.getSequence()); BatchEventProcessor<Record> cb = new BatchEventProcessor<>(ringBuffer, correlatorBarrier, correl); ringBuffer.setGatingSequences(cb.getSequence()); engine.execute(cr); engine.execute(cb); }
From source file:com.linkedin.pinot.controller.helix.core.SegmentDeletionManager.java
SegmentDeletionManager(String localDiskDir, HelixAdmin helixAdmin, String helixClusterName, ZkHelixPropertyStore<ZNRecord> propertyStore) { _localDiskDir = localDiskDir;//from w w w . ja v a2 s .c o m _helixAdmin = helixAdmin; _helixClusterName = helixClusterName; _propertyStore = propertyStore; _executorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { @Override public Thread newThread(Runnable runnable) { Thread thread = new Thread(runnable); thread.setName("PinotHelixResourceManagerExecutorService"); return thread; } }); }
From source file:net.sf.jabref.JabRefExecutorService.java
public void executeWithLowPriorityInOwnThread(final Runnable runnable, String name) { AutoCleanupRunnable target = new AutoCleanupRunnable(runnable, startedThreads); final Thread thread = new Thread(target); target.thread = thread;//from w w w. ja v a 2 s . co m thread.setName("JabRef - " + name + " - low prio"); startedThreads.add(thread); thread.setPriority(Thread.MIN_PRIORITY); thread.start(); }
From source file:info.bitoo.Daemon.java
public void deamonMain() { biToos = new HashMap(); String line = null;/*from w w w.ja va2 s. c o m*/ String filename = null; while (true) { try { line = input.readLine(); filename = input.readLine(); } catch (IOException e) { logger.warn("Error reading a line from input. Continue", e); line = null; filename = null; } if (line != null) { //new request logger.debug("New line from pipe: [" + line + "]"); logger.info("New fetch request for file: [" + filename + "]"); //first line is output pipe path PrintWriter output = null; try { output = new PrintWriter(new FileWriter(line)); } catch (IOException e2) { logger.error("Error opening comunication channel for request: [" + filename + "]. Abort this request", e2); continue; } output.println("BEGIN"); output.flush(); //Create new BiToo BiToo biToo = null; try { biToo = new BiToo(props); biToo.setTorrent(filename); } catch (UnknownHostException e3) { logger.error("Error creating BiToo worker for request: [" + filename + "]. Abort this request", e3); output.println("KO"); output.flush(); output.close(); continue; } catch (MalformedURLException e3) { logger.error("Error creating BiToo worker for request: [" + filename + "]. Abort this request", e3); output.println("KO"); output.flush(); output.close(); continue; } biToo.setListener(this); biToos.put(biToo, output); Thread main = new Thread(biToo); main.setName("BiToo"); main.start(); } try { Thread.sleep(1 * 1000); } catch (InterruptedException e1) { logger.warn("Deamon interrupted while sleeping", e1); } } }