Java 8 ThreadFactory - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ThreadFactory class.

This code example shows how to use the following methods:newThread
    /** 
     * @see org.jgroups.util.ThreadFactory#newThread(java.lang.Runnable, java.lang.String) 
     */ 
    @Override 
    public Thread newThread(Runnable r, String name) {
        return this.renameThread(this.factory.newThread(r), name);
    } 
 
    /** 
     * @see org.jgroups.util.ThreadFactory#newThread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String) 
     */ 
    @Deprecated 
    @Override 
    public Thread newThread(ThreadGroup group, Runnable r, String name) {
        return this.newThread(r, name);
    } 
 
    /** 
     * @see org.jgroups.util.ThreadFactory#setPattern(java.lang.String) 
     */ 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:newThread
	} 
 
 
	@Override 
	public Thread newThread(Runnable runnable) {
		return this.threadFactory.newThread(runnable);
	} 
 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:newThread
        this.threadFactory = threadFactory;
    } 
 
    @Override 
    public void execute(Runnable command) {
        threadFactory.newThread(command).start();
    } 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:newThread
 
    private static void schedule(Thread thread, Runnable task, boolean isWatch) {
        pendingEntries.add(new Entry(thread, task, isWatch));
 
        if (started.compareAndSet(false, true)) {
            Thread watcherThread = threadFactory.newThread(watcher);
            watcherThread.start();
            ThreadDeathWatcher.watcherThread = watcherThread;
        } 
    } 
 
    /** 
     * Waits until the thread of this watcher has no threads to watch and terminates itself. 
     * Because a new watcher thread will be started again on {@link #watch(Thread, Runnable)}, 
     * this operation is only useful when you want to ensure that the watcher thread is terminated 
     * <strong>after</strong> your application is shut down and there's no chance of calling 
     * {@link #watch(Thread, Runnable)} afterwards. 
     * 
     * @return {@code true} if and only if the watcher thread has been terminated 
     */ 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:newThread
		return recordUncaughtExceptionHandler;
	} 
 
	@Override 
	public Thread newThread(Runnable runnable) {
		Thread thread = _threadFactory.newThread(runnable);
 
		thread.setUncaughtExceptionHandler(recordUncaughtExceptionHandler);
 
		return thread;
	} 
 
	private final ThreadFactory _threadFactory =
		Executors.defaultThreadFactory();
	private final RecordUncaughtExceptionHandler 
		recordUncaughtExceptionHandler = new RecordUncaughtExceptionHandler();
 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:newThread
  } 
 
  @Override 
  public void execute(Runnable task)
  { 
    Thread thread = _threadFactory.newThread(task);
    thread.start();
  } 
 
  /** 
   * Executes the callable in a separate thread and return the future to get the result. Note 
   * that this implementation is not efficient and should be used very carefully. 
   * 
   * @param callable 
   * @return the future to get the result. 
   */ 
  public static <V> Future<V> execute(Callable<V> callable)
  { 
    FutureTask<V> futureTask = new FutureTask<V>(callable);
 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:newThread
    } 
 
    @Override 
    public Thread newThread(Runnable r) {
        threadCount.incrementAndGet();
        Thread thread = factory.newThread(r);
        thread.setName(threadName());
        return thread;
    } 
 
    /** 
     * Override this method to customize thread name. 
     */ 
    protected String threadName() {
        return String.format("%s-%d-%d-thread", prefix, factoryCount.intValue(), threadCount.intValue());
    } 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:newThread
        this.delegate = delegate;
    } 
 
    @Override 
    public Thread newThread(Runnable r) {
        Thread thread = delegate.newThread(r);
        thread.setContextClassLoader(contextClassLoader);
        return thread;
    } 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:newThread
    commandId = this.threadIdToCommandId.get(Thread.currentThread().getId());
  } 
 
  @Override 
  public Thread newThread(Runnable r) {
    Thread newThread = threadFactory.newThread(r);
    if (commandId != null) {
      // TODO(#4993059): We need to clean this up when the thread exits 
      // and check that this isn't overwriting an old value. 
      threadIdToCommandId.put(newThread.getId(), commandId);
    } 
    return newThread;
  } 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:newThread
 
	private static class MinPriorityThreadFactory implements ThreadFactory {
		private final ThreadFactory myDefaultThreadFactory = Executors.defaultThreadFactory();
 
		public Thread newThread(Runnable r) {
			final Thread th = myDefaultThreadFactory.newThread(r);
			th.setPriority(Thread.MIN_PRIORITY);
			return th;
		} 
	} 
 
	private static final int IMAGE_LOADING_THREADS_NUMBER = 3; // TODO: how many threads ???
 
	private final ExecutorService myPool = Executors.newFixedThreadPool(IMAGE_LOADING_THREADS_NUMBER, new MinPriorityThreadFactory());
	private final ExecutorService mySinglePool = Executors.newFixedThreadPool(1, new MinPriorityThreadFactory());
 
	private final HashMap<String,LinkedList<Runnable>> myOnImageSyncRunnables = new HashMap<String,LinkedList<Runnable>>();
 
	private class ImageSynchronizedHandler extends Handler {
		@Override 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Java 8 ThreadFactory Questions & Answers:

See Code Examples for Java 8 ThreadFactory Methods: