List of usage examples for java.lang Thread setName
public final synchronized void setName(String name)
From source file:org.alfresco.repo.content.replication.ContentStoreReplicator.java
/** * Kick off the replication thread. If one is already busy, then this method does * nothing.//from www . ja v a2s . c o m */ public synchronized void start() { if (busy) { return; } // create a low-priority, daemon thread to do the work Runnable runnable = new ReplicationRunner(); Thread thread = new Thread(runnable); thread.setName("ContentStoreReplicator"); thread.setPriority(Thread.MIN_PRIORITY); thread.setDaemon(true); // start it thread.start(); busy = true; }
From source file:org.apache.synapse.commons.throttle.core.ThrottleDistributedInstancesCleanupTask.java
public ThrottleDistributedInstancesCleanupTask() { throttleProperties = ThrottleServiceDataHolder.getInstance().getThrottleProperties(); cleanUpPoolSize = Integer.parseInt(throttleProperties.getThrottleDistributedCleanupPoolSize()); noOfTimestampObjectToBeCleared = Long.parseLong(throttleProperties.getThrottleDistributedCleanupAmount()); distributedCleanupEnabled = Boolean .parseBoolean(throttleProperties.getThrottleDistributedCleanupTaskEnable()); maxNonAssociatedCounterCountToClear = Integer .parseInt(throttleProperties.getMaxNonAssociatedCounterCleanupAmount()); if (log.isDebugEnabled()) { log.debug("Throttle window replicator pool size set to " + cleanUpPoolSize); }//from ww w . ja va2 s.co m if (distributedCleanupEnabled) { ScheduledExecutorService executor = Executors.newScheduledThreadPool(cleanUpPoolSize, new ThreadFactory() { public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName("Throttle " + "Distributed Cleanup" + " Task"); return t; } }); String throttleFrequency = throttleProperties.getThrottleContextDistributedCleanupTaskFrequency(); String distributedInstanceExpiry = throttleProperties .getThrottleContextDistributedExpiredInstanceTime(); if (log.isDebugEnabled()) { log.debug("Throttling Cleanup Task Frequency set to " + throttleFrequency); } executor.scheduleAtFixedRate(new CleanupTask(), Integer.parseInt(throttleFrequency), Integer.parseInt(throttleFrequency), TimeUnit.MILLISECONDS); distributedInstanceExpiryMillis = Long.parseLong(distributedInstanceExpiry); } }
From source file:org.blackbananacoin.incubator.extsupernode.SuperNodeApiTester.java
public void mine(final int nblocks, final int numberOfTxInBlock, final int timeout) { Thread miner = new MyMinerThread(numberOfTxInBlock, nblocks, timeout); miner.setName("Miner in the box"); miner.setDaemon(true);/* www .j a v a 2 s. co m*/ miner.start(); }
From source file:de.jackwhite20.japs.client.pub.impl.PublisherImpl.java
public PublisherImpl(List<ClusterServer> clusterServers) { super(clusterServers); this.executorService = Executors.newSingleThreadExecutor(r -> { Thread thread = Executors.defaultThreadFactory().newThread(r); thread.setName("AsyncPublisher Thread"); return thread; });//from w w w . j a v a 2 s .c o m this.asyncPublisher = new AsyncPublisherImpl(executorService, this); }
From source file:org.alfresco.repo.content.caching.quota.StandardQuotaStrategyTest.java
/** * Not a unit test, but useful to fire up a lot of writers that will push the * CachingContentStore's StandardQuotaStrategy beyond the panic threshold. The * behaviour can then be monitored with, for example, a profiler. * /* w w w .ja va2 s .c o m*/ * @throws Exception */ private void concurrencySmokeTest() throws Exception { StandardQuotaStrategyTest.beforeClass(); setUp(); // Need to set maxDeleteWatch count to > 0 // (0 is useful in unit tests, but for real usage must not be used) cleaner.setMaxDeleteWatchCount(1); final int numThreads = 100; Thread[] writers = new Thread[numThreads]; for (int i = 0; i < numThreads; i++) { final String threadName = "WriterThread[" + i + "]"; Runnable runnable = new Runnable() { @Override public void run() { while (true) { writeFile(); pause(); } } private void writeFile() { try { writeSingleFileInMB(1); } catch (IOException error) { throw new RuntimeException(threadName + " couldn't write file.", error); } } private void pause() { long pauseTimeMillis = Math.round(Math.random() * 2000); try { Thread.sleep(pauseTimeMillis); } catch (InterruptedException error) { // Swallow the exception and carry on. System.out.println(threadName + " InterruptedException."); } } }; Thread writerThread = new Thread(runnable); writerThread.setName(threadName); writers[i] = writerThread; writerThread.start(); } }
From source file:com.chicm.cmraft.core.NodeConnectionManager.java
public void collectVote(long term, long lastLogIndex, long lastLogTerm) { int nServers = getRemoteServers().size(); if (nServers <= 0) { return;/*from w ww . java 2s. c o m*/ } ExecutorService executor = Executors.newFixedThreadPool(nServers, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName(getRaftNode().getName() + "-AsyncRpcCaller" + (byte) System.currentTimeMillis()); return t; } }); for (ServerInfo server : getRemoteServers()) { NodeConnection conn = connections.get(server); LOG.debug(getRaftNode().getName() + ": SENDING COLLECTVOTE Request TO: " + server); Thread t = new Thread(new AsynchronousVoteWorker(getRaftNode(), conn, getRaftNode().getServerInfo(), term, lastLogIndex, lastLogTerm)); t.setDaemon(true); executor.execute(t); } }
From source file:org.springframework.cloud.commons.util.InetUtils.java
public InetUtils(final InetUtilsProperties properties) { this.properties = properties; this.executorService = Executors.newSingleThreadExecutor(new ThreadFactory() { @Override/*www. j av a2 s . c o m*/ public Thread newThread(Runnable r) { Thread thread = new Thread(r); thread.setName(InetUtilsProperties.PREFIX); thread.setDaemon(true); return thread; } }); }
From source file:com.fluke.realtime.data.RediffParser.java
@Override public void run() { try {//from ww w. java 2s.com fillData(); worker(); } catch (Exception e) { if (exit != true) { sleep(20); RediffParser parser = new RediffParser(name, date); Thread thread = new Thread(parser); thread.setName(name + "-new"); thread.start(); } } }
From source file:com.chicm.cmraft.core.NodeConnectionManager.java
public void appendEntries(RaftLog logMgr, long lastApplied) { int nServers = getRemoteServers().size(); if (nServers <= 0) { return;//from www .j a va 2 s .c o m } ExecutorService executor = Executors.newFixedThreadPool(nServers, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName(getRaftNode().getName() + "-AsyncRpcCaller" + (byte) System.currentTimeMillis()); return t; } }); for (ServerInfo server : getRemoteServers()) { NodeConnection conn = connections.get(server); long startIndex = logMgr.getFollowerMatchIndex(server) + 1; LOG.info(getRaftNode().getName() + ": SENDING appendEntries Request TO: " + server); Thread t = new Thread(new AsynchronousAppendEntriesWorker(getRaftNode(), conn, getRaftNode().getRaftLog(), getRaftNode().getServerInfo(), getRaftNode().getCurrentTerm(), logMgr.getCommitIndex(), startIndex - 1, logMgr.getLogTerm(startIndex - 1), logMgr.getLogEntries(startIndex, lastApplied), lastApplied)); t.setDaemon(true); executor.execute(t); } }
From source file:com.chicm.cmraft.core.NodeConnectionManager.java
private void appendEntries(long term, ServerInfo leaderId, long leaderCommit, long prevLogIndex, long prevLogTerm, List<RaftLogEntry> entries, long maxIndex) { Preconditions.checkNotNull(entries); int nServers = getRemoteServers().size(); if (nServers <= 0) { return;//from www . j a va2 s .c om } ExecutorService executor = Executors.newFixedThreadPool(nServers, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName(getRaftNode().getName() + "-AsyncRpcCaller" + (byte) System.currentTimeMillis()); return t; } }); for (ServerInfo server : getRemoteServers()) { NodeConnection connection = connections.get(server); LOG.debug(getRaftNode().getName() + ": SENDING appendEntries Request TO: " + server); Thread t = new Thread(new AsynchronousAppendEntriesWorker(getRaftNode(), connection, getRaftNode().getRaftLog(), getRaftNode().getServerInfo(), term, leaderCommit, prevLogIndex, prevLogTerm, entries, maxIndex)); t.setDaemon(true); executor.execute(t); } }