/** * Sets a single-threaded executor to this client. All handlers will be * invoked by this executor. Note that the client executor uses a * user thread (not a daemon thread) that needs to be stopped to * exit the program. * * @return the CoAP client */ public CoapClient useExecutor() { this.executor = Executors.newSingleThreadExecutor(new NamedThreadFactory("CoapClient#")); //$NON-NLS-1$ // activates the executor so that this user thread starts deterministically executor.execute(new Runnable() { public void run() { LOGGER.config("Using a SingleThreadExecutor for the CoapClient"); }; }); return this; }
/** * Creates a new thread for executing a runnable. * <p> * The thread created will be a member of the thread group set during instantiation of this * factory. The thread's priority will be set to {@link Thread#NORM_PRIORITY}. * * @param runnable The runnable that should be executed by the created thread. * @return The newly created thread. * @see #createDaemonThreads() */ @Override public final Thread newThread(Runnable runnable) { final Thread ret = new Thread(group, runnable, prefix + index.getAndIncrement(), 0); ret.setDaemon(createDaemonThreads()); if (ret.getPriority() != Thread.NORM_PRIORITY) { ret.setPriority(Thread.NORM_PRIORITY); } return ret; }
/** * Constructs a new resource that uses the specified amount of threads to * process requests. * * @param name the name * @param threads the number of threads */ public ConcurrentCoapResource(String name, int threads) { super(name); this.threads = threads; setExecutor(Executors.newFixedThreadPool(threads, new NamedThreadFactory("ConcurrentCoapResource-" + name + '#'))); //$NON-NLS-1$ }
/** * Constructs a new resource that uses an executor with as many threads as * there are processors available. * * @param name the name */ public ConcurrentCoapResource(String name) { super(name); this.threads = getAvailableProcessors(); setExecutor(Executors.newFixedThreadPool(threads, new NamedThreadFactory("ConcurrentCoapResource-" + name + '#'))); //$NON-NLS-1$ }
new NamedThreadFactory("CoapServer#")); //$NON-NLS-1$