Package java.util.concurrent

Examples of java.util.concurrent.ThreadFactory.newThread()


        ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class);
        Runnable r = EasyMock.createMock(Runnable.class);
        final int orgPriority = Thread.NORM_PRIORITY + 1;
        Thread t = new Thread();
        t.setPriority(orgPriority);
        EasyMock.expect(wrapped.newThread(r)).andReturn(t);
        EasyMock.replay(wrapped, r);
        BasicThreadFactory factory = builder.wrappedFactory(wrapped).build();
        assertSame("Wrong thread", t, factory.newThread(r));
        assertEquals("Wrong priority", orgPriority, t.getPriority());
        EasyMock.verify(wrapped, r);
View Full Code Here


        ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class);
        Runnable r = EasyMock.createMock(Runnable.class);
        Thread.UncaughtExceptionHandler handler = EasyMock
                .createMock(Thread.UncaughtExceptionHandler.class);
        Thread t = new Thread();
        EasyMock.expect(wrapped.newThread(r)).andReturn(t);
        EasyMock.replay(wrapped, r, handler);
        BasicThreadFactory factory = builder.wrappedFactory(wrapped)
                .uncaughtExceptionHandler(handler).build();
        assertSame("Wrong thread", t, factory.newThread(r));
        assertEquals("Wrong exception handler", handler, t
View Full Code Here

        Runnable r = EasyMock.createMock(Runnable.class);
        Thread.UncaughtExceptionHandler handler = EasyMock
                .createMock(Thread.UncaughtExceptionHandler.class);
        Thread t = new Thread();
        t.setUncaughtExceptionHandler(handler);
        EasyMock.expect(wrapped.newThread(r)).andReturn(t);
        EasyMock.replay(wrapped, r, handler);
        BasicThreadFactory factory = builder.wrappedFactory(wrapped).build();
        assertSame("Wrong thread", t, factory.newThread(r));
        assertEquals("Wrong exception handler", handler, t
                .getUncaughtExceptionHandler());
View Full Code Here

    ThreadFactory factory = mock(ThreadFactory.class);

    channel = new StreamedDuplexChannel(factory, responder, decoder, source, 32);

    when(source.open()).thenReturn(stream);
    when(factory.newThread(isA(StreamedDuplexChannel.Reader.class))).thenReturn(threadRead);
    when(factory.newThread(isA(StreamedDuplexChannel.Writer.class))).thenReturn(threadWrite);
  }

  @Test(expected = NullPointerException.class)
  public void testChannelListenerProtection() {
View Full Code Here

    channel = new StreamedDuplexChannel(factory, responder, decoder, source, 32);

    when(source.open()).thenReturn(stream);
    when(factory.newThread(isA(StreamedDuplexChannel.Reader.class))).thenReturn(threadRead);
    when(factory.newThread(isA(StreamedDuplexChannel.Writer.class))).thenReturn(threadWrite);
  }

  @Test(expected = NullPointerException.class)
  public void testChannelListenerProtection() {
    channel.setChannelListener(null);
View Full Code Here

  }

  @Test public void
  defaultThreadFactoryMustCreateThreadsWithStormpotNameSignature() {
    ThreadFactory factory = config.getThreadFactory();
    Thread thread = factory.newThread(null);
    assertThat(thread.getName(), containsString("Stormpot"));
  }

  @Test public void
  threadFactoryMustBeSettable() {
View Full Code Here

        ? builder.backingThreadFactory
        : Executors.defaultThreadFactory();
    final AtomicLong count = (nameFormat != null) ? new AtomicLong(0) : null;
    return new ThreadFactory() {
      @Override public Thread newThread(Runnable runnable) {
        Thread thread = backingThreadFactory.newThread(runnable);
        if (nameFormat != null) {
          thread.setName(String.format(nameFormat, count.getAndIncrement()));
        }
        if (daemon != null) {
          thread.setDaemon(daemon);
View Full Code Here

    builder = new ThreadFactoryBuilder();
  }

  public void testThreadFactoryBuilder_defaults() throws InterruptedException {
    ThreadFactory threadFactory = builder.build();
    Thread thread = threadFactory.newThread(monitoredRunnable);
    checkThreadPoolName(thread, 1);

    Thread defaultThread =
        Executors.defaultThreadFactory().newThread(monitoredRunnable);
    assertEquals(defaultThread.isDaemon(), thread.isDaemon());
View Full Code Here

    thread.join();
    assertTrue(completed);

    // Creating a new thread from the same ThreadFactory will have the same
    // pool ID but a thread ID of 2.
    Thread thread2 = threadFactory.newThread(monitoredRunnable);
    checkThreadPoolName(thread2, 2);
    assertEquals(
        thread.getName().substring(0, thread.getName().lastIndexOf('-')),
        thread2.getName().substring(0, thread.getName().lastIndexOf('-')));
View Full Code Here

        thread.getName().substring(0, thread.getName().lastIndexOf('-')),
        thread2.getName().substring(0, thread.getName().lastIndexOf('-')));

    // Building again should give us a different pool ID.
    ThreadFactory threadFactory2 = builder.build();
    Thread thread3 = threadFactory2.newThread(monitoredRunnable);
    checkThreadPoolName(thread3, 1);
    ASSERT.that(
        thread2.getName().substring(0, thread.getName().lastIndexOf('-')))
        .isNotEqualTo(
            thread3.getName().substring(0, thread.getName().lastIndexOf('-')));
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.