List of usage examples for java.lang Thread setName
public final synchronized void setName(String name)
From source file:org.apache.hadoop.hdfs.server.blockmanagement.DefaultServerLookup.java
private void startCleanupDaemon(final String con) { Runnable runnable = new Runnable() { @Override//from w ww . j ava2s . c o m public void run() { while (_running.get()) { try { runLayoutCleanup(con); } catch (BlurException e) { LOG.error("Unknown error.", e); } catch (TException e) { LOG.error("Unknown error.", e); } try { Thread.sleep(_pollTime); } catch (InterruptedException e) { LOG.error("Unknown interruption.", e); return; } } } }; Thread thread = new Thread(runnable); thread.setDaemon(true); thread.setName("Blur Cleanup for [" + con + "]"); thread.start(); _daemons.add(thread); }
From source file:org.apache.hadoop.hdfs.server.blockmanagement.DefaultServerLookup.java
private void startWatchDaemon(final String con) { Runnable runnable = new Runnable() { @Override/* ww w .ja v a 2 s. c om*/ public void run() { while (_running.get()) { try { runLayoutUpdate(con); } catch (BlurException e) { LOG.error("Unknown error.", e); } catch (TException e) { LOG.error("Unknown error.", e); } try { Thread.sleep(_pollTime); } catch (InterruptedException e) { LOG.error("Unknown interruption.", e); return; } } } }; Thread thread = new Thread(runnable); thread.setDaemon(true); thread.setName("Blur Watch for [" + con + "]"); thread.start(); _daemons.add(thread); }
From source file:com.datatorrent.lib.appdata.query.QueryManagerAsynchronousTest.java
@Test public void stressTest() throws Exception { final int totalTuples = 100000; final int batchSize = 100; final double waitMillisProb = .01; AppDataWindowEndQueueManager<MockQuery, Void> queueManager = new AppDataWindowEndQueueManager<MockQuery, Void>(); DefaultOutputPort<String> outputPort = new DefaultOutputPort<String>(); CollectorTestSink<MockResult> sink = new CollectorTestSink<MockResult>(); TestUtils.setSink(outputPort, sink); MessageSerializerFactory msf = new MessageSerializerFactory(new ResultFormatter()); QueryManagerAsynchronous<MockQuery, Void, MutableLong, MockResult> queryManagerAsynch = new QueryManagerAsynchronous<>( outputPort, queueManager, new NOPQueryExecutor(waitMillisProb), msf, Thread.currentThread()); Thread producerThread = new Thread( new ProducerThread(queueManager, totalTuples, batchSize, waitMillisProb)); producerThread.start();/*w w w. j av a 2s .c o m*/ producerThread.setName("Producer Thread"); long startTime = System.currentTimeMillis(); queryManagerAsynch.setup(null); int numWindows = 0; for (; sink.collectedTuples.size() < totalTuples && ((System.currentTimeMillis() - startTime) < 60000); numWindows++) { queryManagerAsynch.beginWindow(numWindows); Thread.sleep(100); queryManagerAsynch.endWindow(); } producerThread.stop(); queryManagerAsynch.teardown(); try { Thread.sleep(1000); } catch (InterruptedException e) { //Do Nothing } Assert.assertEquals(totalTuples, sink.collectedTuples.size()); }
From source file:com.adaptris.core.jms.ActiveJmsConnectionErrorHandler.java
@Override public void init() throws CoreException { super.init(); try {/*from w w w . j a va 2 s .c om*/ MyExceptionHandler handler = new MyExceptionHandler(); CountDownLatch verifierThreadGate = new CountDownLatch(1); verifier = new JmsConnectionVerifier(idForLogging, verifierThreadGate); Thread verifierThread = new ManagedThreadFactory(getClass().getSimpleName()).newThread(verifier); verifierThread.setName("JmsConnectionErrorHandler for " + idForLogging); verifierThread.setUncaughtExceptionHandler(handler); verifierThread.start(); boolean actuallyStarted = verifierThreadGate.await(DEFAULT_MAX_WAIT_FOR_START.toMilliseconds(), TimeUnit.MILLISECONDS); if (!actuallyStarted) { if (handler.hasError()) { ExceptionHelper.rethrowCoreException(handler.lastCaughtException); } else { throw new CoreException("Failed to start connection error handler"); } } if (additionalLogging()) { log.debug("ActiveJmsConnectionErrorHandler for {} started", idForLogging); } } catch (Exception e) { ExceptionHelper.rethrowCoreException(e); } }
From source file:org.josso.selfservices.password.PasswordManagementServiceImpl.java
public void initialize() { // Start session monitor. monitor = new PasswordManagementMonitor(this); Thread t = new Thread(monitor); t.setName("JOSSOPasswordManagementMonitor"); t.start();/*from ww w .j av a 2s .co m*/ }
From source file:ow.tool.dhtshell.Main.java
private Shell<DHT<String>> init(String[] args, InputStream in, PrintStream out, boolean interactive) { int shellPort = SHELL_PORT; AccessController ac = null;/*from w ww. j a v a 2 s .c o m*/ boolean disableStdin = false; boolean invokeXMLRPCServer = false; boolean showMapOnWebInterface = false; int oasisPort = -1; // parse command-line arguments Options opts = this.getInitialOptions(); opts.addOption("p", "port", true, "port number"); opts.addOption("A", "acl", true, "access control list file"); opts.addOption("n", "disablestdin", false, "disable standard input"); opts.addOption("W", "web", false, "invoke a web/XML-RPC server"); opts.addOption("M", "showmap", false, "show a Google Map on a web interface"); opts.addOption("O", "oasis", true, "invoke an OASIS responder"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(opts, args); } catch (ParseException e) { System.out.println("There is an invalid option."); e.printStackTrace(); System.exit(1); } parser = null; opts = null; String optVal; optVal = cmd.getOptionValue('p'); if (optVal != null) { shellPort = Integer.parseInt(optVal); } optVal = cmd.getOptionValue("A"); if (optVal != null) { try { ac = new AccessController(optVal); } catch (IOException e) { System.err.println("An Exception thrown:"); e.printStackTrace(); return null; } } if (cmd.hasOption('n')) { disableStdin = true; } if (cmd.hasOption('W')) { invokeXMLRPCServer = true; } if (cmd.hasOption('M')) { showMapOnWebInterface = true; } optVal = cmd.getOptionValue("O"); if (optVal != null) { oasisPort = Integer.parseInt(optVal); } // parse remaining arguments // and initialize a DHT DHT<String> dht = null; try { dht = super.initialize(Signature.APPLICATION_ID_DHT_SHELL, (short) 0x10000, DHTFactory.getDefaultConfiguration(), COMMAND, cmd); } catch (Exception e) { System.err.println("An Exception thrown:"); e.printStackTrace(); return null; } cmd = null; // start an XML-RPC server XmlRpcDHTServer rpcServer = null; if (invokeXMLRPCServer) { rpcServer = new XmlRpcDHTServer(dht, showMapOnWebInterface); int xmlrpcPort = dht.getConfiguration().getContactPort() + XMLRPC_PORT_DIFF; try { String url = rpcServer.start(xmlrpcPort, XMLRPC_PORT_RANGE); System.out.println("Web and XML-RPC server: " + url); } catch (Exception e) { System.err.println("Failed to start a web server."); e.printStackTrace(); return null; } } // start an OASIS responder if (oasisPort >= 1 && oasisPort < 65535) { OASISResponder s = null; try { s = new OASISResponder(oasisPort); } catch (IOException e) { System.err.println("Failed to start an OASIS responder on port " + oasisPort); e.printStackTrace(); return null; } Thread t = new Thread(s); t.setName("OASIS responder"); t.setDaemon(true); t.start(); System.out.println("OASIS responder: port " + oasisPort); } // start a ShellServer ShellServer<DHT<String>> shellServ = new ShellServer<DHT<String>>(commandTable, commandList, new ShowPromptPrinter(), new NoCommandPrinter(), null, dht, shellPort, ac); if (rpcServer != null) shellServ.addInterruptible(rpcServer); // interrupted by "halt" command Shell<DHT<String>> stdioShell = null; if (disableStdin) { try { Thread.sleep(Long.MAX_VALUE); } catch (InterruptedException e) { } } else { stdioShell = new Shell<DHT<String>>(in, out, shellServ, dht, interactive); } return stdioShell; }
From source file:org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.FsDatasetAsyncDiskService.java
private void addExecutorForVolume(final File volume) { ThreadFactory threadFactory = new ThreadFactory() { int counter = 0; @Override/*from w w w .jav a 2 s. c om*/ public Thread newThread(Runnable r) { int thisIndex; synchronized (this) { thisIndex = counter++; } Thread t = new Thread(threadGroup, r); t.setName("Async disk worker #" + thisIndex + " for volume " + volume); return t; } }; ThreadPoolExecutor executor = new ThreadPoolExecutor(CORE_THREADS_PER_VOLUME, MAXIMUM_THREADS_PER_VOLUME, THREADS_KEEP_ALIVE_SECONDS, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), threadFactory); // This can reduce the number of running threads executor.allowCoreThreadTimeOut(true); executors.put(volume, executor); }
From source file:de.uni_potsdam.hpi.asg.common.io.Invoker.java
private ProcessReturn invoke(String[] cmd, List<String> params, File folder, int timeout) { List<String> command = new ArrayList<String>(); command.addAll(Arrays.asList(cmd)); command.addAll(params);/*from w w w . ja va2 s . c o m*/ ProcessReturn retVal = new ProcessReturn(Arrays.asList(cmd), params); Process process = null; try { logger.debug("Exec command: " + command.toString()); //System.out.println(timeout + ": " + command.toString()); ProcessBuilder builder = new ProcessBuilder(command); builder.directory(folder); builder.environment(); // bugfix setting env in test-mode (why this works? i dont know..) process = builder.start(); Thread timeoutThread = null; if (timeout > 0) { timeoutThread = new Thread(new Timeout(Thread.currentThread(), timeout)); timeoutThread.setName("Timout for " + command.toString()); timeoutThread.start(); } IOStreamReader ioreader = new IOStreamReader(process); Thread streamThread = new Thread(ioreader); streamThread.setName("StreamReader for " + command.toString()); streamThread.start(); process.waitFor(); streamThread.join(); if (timeoutThread != null) { timeoutThread.interrupt(); } String out = ioreader.getResult(); //System.out.println(out); if (out == null) { //System.out.println("out = null"); retVal.setStatus(Status.noio); } retVal.setCode(process.exitValue()); retVal.setStream(out); retVal.setStatus(Status.ok); } catch (InterruptedException e) { process.destroy(); retVal.setTimeout(timeout); retVal.setStatus(Status.timeout); } catch (IOException e) { logger.error(e.getLocalizedMessage()); retVal.setStatus(Status.ioexception); } return retVal; }
From source file:org.pentaho.osgi.i18n.impl.LocalizationManager.java
public void bundleChanged(Bundle bundle) throws IOException, ParseException { boolean rebuildCache; synchronized (configMap) { rebuildCache = configMap.remove(bundle.getBundleId()) != null; }//from w w w .j a v a 2 s . c o m if (bundle.getState() == Bundle.ACTIVE) { Map<String, OSGIResourceBundleFactory> configEntry = new HashMap<String, OSGIResourceBundleFactory>(); OSGIResourceBundleFactory bundleFactory; Enumeration<URL> urlEnumeration = bundle.findEntries(OSGIResourceNamingConvention.RESOURCES_ROOT_FOLDER, "*" + OSGIResourceNamingConvention.RESOURCES_DEFAULT_EXTENSION + "*", true); if (urlEnumeration != null) { while (urlEnumeration.hasMoreElements()) { URL url = urlEnumeration.nextElement(); if (url != null) { String fileName = url.getFile(); String relativeName = fileName; String name = getPropertyName(fileName); int priority = OSGIResourceNamingConvention.getPropertyPriority(fileName); bundleFactory = new OSGIResourceBundleFactory(name, relativeName, url, priority); configEntry.put(relativeName, bundleFactory); rebuildCache = true; } } } if (!configEntry.isEmpty()) { synchronized (configMap) { configMap.put(bundle.getBundleId(), configEntry); } rebuildCache = true; } } if (rebuildCache) { synchronized (configMap) { if (executorService == null) { executorService = Executors.newSingleThreadExecutor(new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread thread = Executors.defaultThreadFactory().newThread(r); thread.setDaemon(true); thread.setName("Localization pool"); return thread; } }); } cache = executorService.submit(new OSGIResourceBundleCacheCallable( new HashMap<Long, Map<String, OSGIResourceBundleFactory>>(configMap))); } } }
From source file:org.apache.hadoop.yarn.event.AsyncDispatcher.java
@SuppressWarnings("unchecked") protected void dispatch(Event event) { //all events go thru this loop if (LOG.isDebugEnabled()) { LOG.debug("Dispatching the event " + event.getClass().getName() + "." + event.toString()); }//from w w w . ja v a 2s. co m Class<? extends Enum> type = event.getType().getDeclaringClass(); try { EventHandler handler = eventDispatchers.get(type); if (handler != null) { handler.handle(event); } else { throw new Exception("No handler for registered for " + type); } } catch (Throwable t) { //TODO Maybe log the state of the queue LOG.fatal("Error in dispatcher thread", t); // If serviceStop is called, we should exit this thread gracefully. if (exitOnDispatchException && (ShutdownHookManager.get().isShutdownInProgress()) == false && stopped == false) { Thread shutDownThread = new Thread(createShutDownThread()); shutDownThread.setName("AsyncDispatcher ShutDown handler"); shutDownThread.start(); } } }