@Override protected ThreadRenamingRunnable newThreadRenamingRunnable(int id, ThreadNameDeterminer determiner) { return new ThreadRenamingRunnable(this, "New I/O server boss #" + id, determiner); }
public void run() { final Thread currentThread = Thread.currentThread(); final String oldThreadName = currentThread.getName(); final String newThreadName = getNewThreadName(oldThreadName); // Change the thread name before starting the actual runnable. boolean renamed = false; if (!oldThreadName.equals(newThreadName)) { try { currentThread.setName(newThreadName); renamed = true; } catch (SecurityException e) { logger.debug( "Failed to rename a thread " + "due to security restriction.", e); } } // Run the actual runnable and revert the name back when it ends. try { runnable.run(); } finally { if (renamed) { // Revert the name back if the current thread was renamed. // We do not check the exception here because we know it works. currentThread.setName(oldThreadName); } } }
private String getNewThreadName(String currentThreadName) { String newThreadName = null; try { ThreadNameDeterminer nameDeterminer = determiner; if (nameDeterminer == null) { nameDeterminer = getThreadNameDeterminer(); } newThreadName = nameDeterminer.determineThreadName( currentThreadName, proposedThreadName); } catch (Throwable t) { logger.warn("Failed to determine the thread name", t); } return newThreadName == null? currentThreadName : newThreadName; } }
/** * Creates a new instance of {@link AbstractCoapApplication}. * * @param applicationName the given name of this application (for logging only) */ protected AbstractCoapApplication(String applicationName) { this.applicationName = applicationName; ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(applicationName + " I/O Worker #%d").build(); ThreadRenamingRunnable.setThreadNameDeterminer(new ThreadNameDeterminer() { @Override public String determineThreadName(String currentThreadName, String proposedThreadName) throws Exception { return null; } }); // determine number of I/O threads and create thread pool executor of that size int ioThreads = Math.max(Runtime.getRuntime().availableProcessors() * 2, 4); this.executor = new ScheduledThreadPoolExecutor(ioThreads, threadFactory); // this.executor = new SynchronizedExecutor(ioThreads, threadFactory); }
@Override protected ThreadRenamingRunnable newThreadRenamingRunnable(int id, ThreadNameDeterminer determiner) { return new ThreadRenamingRunnable(this, "New I/O boss #" + id, determiner); }
private String getNewThreadName(String currentThreadName) { String newThreadName = null; try { ThreadNameDeterminer nameDeterminer = determiner; if (nameDeterminer == null) { nameDeterminer = getThreadNameDeterminer(); } newThreadName = nameDeterminer.determineThreadName( currentThreadName, proposedThreadName); } catch (Throwable t) { logger.warn("Failed to determine the thread name", t); } return newThreadName == null? currentThreadName : newThreadName; } }
public void run() { final Thread currentThread = Thread.currentThread(); final String oldThreadName = currentThread.getName(); final String newThreadName = getNewThreadName(oldThreadName); // Change the thread name before starting the actual runnable. boolean renamed = false; if (!oldThreadName.equals(newThreadName)) { try { currentThread.setName(newThreadName); renamed = true; } catch (SecurityException e) { logger.debug( "Failed to rename a thread " + "due to security restriction.", e); } } // Run the actual runnable and revert the name back when it ends. try { runnable.run(); } finally { if (renamed) { // Revert the name back if the current thread was renamed. // We do not check the exception here because we know it works. currentThread.setName(oldThreadName); } } }
@Override protected ThreadRenamingRunnable newThreadRenamingRunnable(int id, ThreadNameDeterminer determiner) { return new ThreadRenamingRunnable(this, "New I/O worker #" + id, determiner); }
workerThread = threadFactory.newThread(new ThreadRenamingRunnable( worker, "Hashed wheel timer #" + id.incrementAndGet(), determiner));
new ThreadRenamingRunnable( new OioWorker(channel), "Old I/O client worker (" + channel + ')',
DeadLockProofWorker.start( workerExecutor, new ThreadRenamingRunnable( new OioWorker(acceptedChannel), "Old I/O server worker (parentId: " +
private void bind( OioServerSocketChannel channel, ChannelFuture future, SocketAddress localAddress) { boolean bound = false; boolean bossStarted = false; try { channel.socket.bind(localAddress, channel.getConfig().getBacklog()); bound = true; future.setSuccess(); localAddress = channel.getLocalAddress(); fireChannelBound(channel, localAddress); Executor bossExecutor = ((OioServerSocketChannelFactory) channel.getFactory()).bossExecutor; DeadLockProofWorker.start( bossExecutor, new ThreadRenamingRunnable( new Boss(channel), "Old I/O server boss (" + channel + ')', determiner)); bossStarted = true; } catch (Throwable t) { future.setFailure(t); fireExceptionCaught(channel, t); } finally { if (!bossStarted && bound) { close(channel, future); } } }
private void bind( OioDatagramChannel channel, ChannelFuture future, SocketAddress localAddress) { boolean bound = false; boolean workerStarted = false; try { channel.socket.bind(localAddress); bound = true; // Fire events future.setSuccess(); fireChannelBound(channel, channel.getLocalAddress()); // Start the business. DeadLockProofWorker.start( workerExecutor, new ThreadRenamingRunnable( new OioDatagramWorker(channel), "Old I/O datagram worker (" + channel + ')', determiner)); workerStarted = true; } catch (Throwable t) { future.setFailure(t); fireExceptionCaught(channel, t); } finally { if (bound && !workerStarted) { AbstractOioWorker.close(channel, future); } } }
new ThreadRenamingRunnable( new OioDatagramWorker(channel), threadName, determiner)); } else {
@Override protected ThreadRenamingRunnable newThreadRenamingRunnable(int id, ThreadNameDeterminer determiner) { return new ThreadRenamingRunnable(this, "New I/O server boss #" + id, determiner); }
@Override protected ThreadRenamingRunnable newThreadRenamingRunnable(int id, ThreadNameDeterminer determiner) { return new ThreadRenamingRunnable(this, "New I/O boss #" + id, determiner); }
@Override protected ThreadRenamingRunnable newThreadRenamingRunnable(int id, ThreadNameDeterminer determiner) { return new ThreadRenamingRunnable(this, "New I/O server boss #" + id, determiner); }
@Override protected ThreadRenamingRunnable newThreadRenamingRunnable(int id, ThreadNameDeterminer determiner) { return new ThreadRenamingRunnable(this, "New I/O udp boss #" + id, determiner); }
@Override protected ThreadRenamingRunnable newThreadRenamingRunnable(int id, ThreadNameDeterminer determiner) { return new ThreadRenamingRunnable(this, "New I/O worker #" + id, determiner); }
public AgronaClientChannelFactory() { this.channelSink = new AgronaClientChannelSink(); // TODO: boss pool this.boss = new AgronaClientBoss(); this.bossExecutor = Executors.newFixedThreadPool(1); this.bossExecutor.execute(new ThreadRenamingRunnable(boss, "Agrona boss")); // TODO: worker pool this.worker = new AgronaWorker(); this.workerExecutor = Executors.newFixedThreadPool(1); this.workerExecutor.execute(new ThreadRenamingRunnable(worker, "Agrona worker")); }