List of usage examples for java.lang Thread setName
public final synchronized void setName(String name)
From source file:org.openstreetmap.josm.data.cache.JCSCachedTileLoaderJob.java
@Override public void run() { final Thread currentThread = Thread.currentThread(); final String oldName = currentThread.getName(); currentThread.setName("JCS Downloading: " + getUrlNoException()); LOG.log(Level.FINE, "JCS - starting fetch of url: {0} ", getUrlNoException()); ensureCacheElement();// w w w . ja v a2s. co m try { // try to fetch from cache if (!force && cacheElement != null && isCacheElementValid() && isObjectLoadable()) { // we got something in cache, and it's valid, so lets return it LOG.log(Level.FINE, "JCS - Returning object from cache: {0}", getCacheKey()); finishLoading(LoadResult.SUCCESS); return; } // try to load object from remote resource if (loadObject()) { finishLoading(LoadResult.SUCCESS); } else { // if loading failed - check if we can return stale entry if (isObjectLoadable()) { // try to get stale entry in cache finishLoading(LoadResult.SUCCESS); LOG.log(Level.FINE, "JCS - found stale object in cache: {0}", getUrlNoException()); } else { // failed completely finishLoading(LoadResult.FAILURE); } } } finally { executionFinished(); currentThread.setName(oldName); } }
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 ww. j a va2 s . c om } }
From source file:org.apache.servicemix.nmr.core.ChannelImpl.java
/** * Synchronously send the exchange//from w w w .ja v a 2s . com * * @param exchange the exchange to send * @param timeout time to wait in milliseconds * @return <code>true</code> if the exchange has been processed succesfully */ public boolean sendSync(Exchange exchange, long timeout) { InternalExchange e = (InternalExchange) exchange; Semaphore lock = e.getRole() == Role.Consumer ? e.getConsumerLock(true) : e.getProviderLock(true); dispatch(e); Thread thread = Thread.currentThread(); String original = thread.getName(); try { if (timeout > 0) { if (!lock.tryAcquire(timeout, TimeUnit.MILLISECONDS)) { throw new TimeoutException(); } } else { thread.setName(original + " (waiting for exchange " + exchange.getId() + ")"); lock.acquire(); } e.setRole(e.getRole() == Role.Consumer ? Role.Provider : Role.Consumer); } catch (InterruptedException ex) { exchange.setError(ex); for (ExchangeListener l : nmr.getListenerRegistry().getListeners(ExchangeListener.class)) { l.exchangeFailed(exchange); } return false; } catch (TimeoutException ex) { exchange.setError(new AbortedException(ex)); for (ExchangeListener l : nmr.getListenerRegistry().getListeners(ExchangeListener.class)) { l.exchangeFailed(exchange); } return false; } finally { thread.setName(original); } return true; }
From source file:org.springframework.jmx.support.ConnectorServerFactoryBean.java
/** * Start the connector server. If the <code>threaded</code> flag is set to <code>true</code>, * the <code>JMXConnectorServer</code> will be started in a separate thread. * If the <code>daemon</code> flag is set to <code>true</code>, that thread will be * started as a daemon thread./*from w w w .j av a 2 s .com*/ * @throws JMException if a problem occured when registering the connector server * with the <code>MBeanServer</code> * @throws IOException if there is a problem starting the connector server */ public void afterPropertiesSet() throws JMException, IOException { if (this.server == null) { this.server = JmxUtils.locateMBeanServer(); } // Create the JMX service URL. JMXServiceURL url = new JMXServiceURL(this.serviceUrl); // Create the connector server now. this.connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, this.environment, this.server); // Do we want to register the connector with the MBean server? if (this.objectName != null) { this.server.registerMBean(this.connectorServer, this.objectName); } try { if (this.threaded) { // Start the connector server asynchronously (in a separate thread). Thread connectorThread = new Thread() { public void run() { try { connectorServer.start(); } catch (IOException ex) { throw new DelayedConnectorStartException(ex); } } }; connectorThread.setName("JMX Connector Thread [" + this.serviceUrl + "]"); connectorThread.setDaemon(this.daemon); connectorThread.start(); } else { // Start the connector server in the same thread. this.connectorServer.start(); } if (logger.isInfoEnabled()) { logger.info("JMX connector server started: " + this.connectorServer); } } catch (IOException ex) { // Unregister the connector server if startup failed. unregisterConnectorServer(); throw ex; } }
From source file:immf.AppNotifications.java
public AppNotifications(Config conf, StatusManager status) { this.status = status; this.email = conf.getForwardPushEmail(); this.password = conf.getForwardPushPassword(); this.message = conf.getForwardPushMessage(); if (this.message == null) this.message = Message; this.sound = soundFile(conf.getForwardPushSound()); this.iconUrl = conf.getForwardPushIconUrl(); if (this.iconUrl.isEmpty()) this.iconUrl = IconUrl; this.pushFromInfo = conf.isForwardPushFrom(); this.pushSubjectInfo = conf.isForwardPushSubject(); this.pushReplyButton = conf.isForwardPushReplyButton(); this.dnsCache = conf.isForwardPushUseDnsCache(); this.credentials = status.getPushCredentials(); if (this.credentials == null) this.credentials = ""; if (this.email.length() > 0 && this.password.length() > 0) { Thread t = new Thread(this); t.setName("AppNotifications"); t.setDaemon(true);//from ww w . ja v a2 s. co m t.start(); } else { if (this.credentials.length() > 0) this.setCredentials(""); } }
From source file:com.persinity.ndt.datamutator.DataMutator.java
private void startNewLoader(final boolean startPaused) { final LoadBase loadExecutor = buildTestLoadExecutor(config.getLoadType(), entityFactory, entityPoolUtil); if (startPaused) { loadExecutor.requestPause();/*from ww w . j av a2s . c o m*/ } int indx; synchronized (lock) { loadExecutors.add(loadExecutor); indx = loadExecutors.size(); } final Thread th = new Thread(loadExecutor); th.setName("DataMutator-" + indx); th.start(); synchronized (lock) { threads.add(th); } }
From source file:org.apache.nifi.processors.standard.ListenSyslog.java
@OnScheduled public void onScheduled(final ProcessContext context) throws IOException { final int port = context.getProperty(PORT).asInteger(); final int bufferSize = context.getProperty(RECV_BUFFER_SIZE).asDataSize(DataUnit.B).intValue(); final int maxChannelBufferSize = context.getProperty(MAX_SOCKET_BUFFER_SIZE).asDataSize(DataUnit.B) .intValue();//from w w w .j av a 2 s.c o m final int maxMessageQueueSize = context.getProperty(MAX_MESSAGE_QUEUE_SIZE).asInteger(); final String protocol = context.getProperty(PROTOCOL).getValue(); final String nicIPAddressStr = context.getProperty(NETWORK_INTF_NAME).evaluateAttributeExpressions() .getValue(); final String charSet = context.getProperty(CHARSET).getValue(); final String msgDemarcator = context.getProperty(MESSAGE_DELIMITER).getValue().replace("\\n", "\n") .replace("\\r", "\r").replace("\\t", "\t"); messageDemarcatorBytes = msgDemarcator.getBytes(Charset.forName(charSet)); final int maxConnections; if (UDP_VALUE.getValue().equals(protocol)) { maxConnections = 1; } else { maxConnections = context.getProperty(MAX_CONNECTIONS).asLong().intValue(); } bufferPool = new LinkedBlockingQueue<>(maxConnections); for (int i = 0; i < maxConnections; i++) { bufferPool.offer(ByteBuffer.allocate(bufferSize)); } parser = new SyslogParser(Charset.forName(charSet)); syslogEvents = new LinkedBlockingQueue<>(maxMessageQueueSize); InetAddress nicIPAddress = null; if (!StringUtils.isEmpty(nicIPAddressStr)) { NetworkInterface netIF = NetworkInterface.getByName(nicIPAddressStr); nicIPAddress = netIF.getInetAddresses().nextElement(); } // create either a UDP or TCP reader and call open() to bind to the given port final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE) .asControllerService(SSLContextService.class); channelDispatcher = createChannelReader(protocol, bufferPool, syslogEvents, maxConnections, sslContextService, Charset.forName(charSet)); channelDispatcher.open(nicIPAddress, port, maxChannelBufferSize); final Thread readerThread = new Thread(channelDispatcher); readerThread.setName("ListenSyslog [" + getIdentifier() + "]"); readerThread.setDaemon(true); readerThread.start(); }
From source file:com.microsoft.tfs.client.common.server.cache.buildstatus.BuildStatusManager.java
public BuildStatusManager(final TFSTeamProjectCollection connection) { Check.notNull(connection, "connection"); //$NON-NLS-1$ this.connection = connection; loadConfiguration();/* w w w. java 2 s. co m*/ loadExtensionListeners(); final Thread refreshThread = new Thread(new BuildStatusManagerRefreshWorker()); refreshThread.setName("Build Status Manager"); //$NON-NLS-1$ refreshThread.start(); }
From source file:com.zimbra.cs.mime.Mime.java
/** Returns an {@code InputStream} to the content of a {@code MimeMessage} * by starting a thread that serves up its content to a {@code * PipedOutputStream}. This workaround is necessary because JavaMail does * not provide {@code InputStream} access to the content. */ public static InputStream getInputStream(MimeMessage mm) throws IOException { // if (isZimbraJavaMailShim(mm)) { // return ((ZMimeMessage) mm).getMessageStream(); // }//from www . ja v a 2s.c om // Nasty hack because JavaMail doesn't provide an InputStream accessor // to the entire RFC 822 content of a MimeMessage. Start a thread that // serves up the content of the MimeMessage via PipedOutputStream. PipedInputStream in = new PipedInputStream(); PipedOutputStream out = new PipedOutputStream(in); Thread thread = new Thread(new MimeMessageOutputThread(mm, out)); thread.setName("MimeMessageThread"); thread.start(); return in; }
From source file:bamboo.trove.full.FullReindexWarcManager.java
@Override public void start() { if (!running && !stopping) { log.info("Starting..."); running = true;//from w w w. j ava 2 s. co m Thread me = new Thread(this); me.setName(getName()); me.start(); } }