Package java.util.concurrent

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


    public void testNewThreadNamingPattern() {
        ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class);
        Runnable r = EasyMock.createMock(Runnable.class);
        final int count = 12;
        for (int i = 0; i < count; i++) {
            EasyMock.expect(wrapped.newThread(r)).andReturn(new Thread());
        }
        EasyMock.replay(wrapped, r);
        BasicThreadFactory factory = builder.wrappedFactory(wrapped)
                .namingPattern(PATTERN).build();
        for (int i = 0; i < count; i++) {
View Full Code Here


    public void testNewThreadNoNamingPattern() {
        ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class);
        Runnable r = EasyMock.createMock(Runnable.class);
        final String name = "unchangedThreadName";
        Thread t = new Thread(name);
        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("Name was changed", name, t.getName());
        EasyMock.verify(wrapped, r);
View Full Code Here

     */
    private void checkDaemonFlag(boolean flag) {
        ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class);
        Runnable r = EasyMock.createMock(Runnable.class);
        Thread t = new Thread();
        EasyMock.expect(wrapped.newThread(r)).andReturn(t);
        EasyMock.replay(wrapped, r);
        BasicThreadFactory factory = builder.wrappedFactory(wrapped).daemon(
                flag).build();
        assertSame("Wrong thread", t, factory.newThread(r));
        assertEquals("Wrong daemon flag", flag, t.isDaemon());
View Full Code Here

        Runnable r1 = EasyMock.createMock(Runnable.class);
        Runnable r2 = EasyMock.createMock(Runnable.class);
        Thread t1 = new Thread();
        Thread t2 = new Thread();
        t1.setDaemon(true);
        EasyMock.expect(wrapped.newThread(r1)).andReturn(t1);
        EasyMock.expect(wrapped.newThread(r2)).andReturn(t2);
        EasyMock.replay(wrapped, r1, r2);
        BasicThreadFactory factory = builder.wrappedFactory(wrapped).build();
        assertSame("Wrong thread 1", t1, factory.newThread(r1));
        assertTrue("No daemon thread", t1.isDaemon());
View Full Code Here

        Runnable r2 = EasyMock.createMock(Runnable.class);
        Thread t1 = new Thread();
        Thread t2 = new Thread();
        t1.setDaemon(true);
        EasyMock.expect(wrapped.newThread(r1)).andReturn(t1);
        EasyMock.expect(wrapped.newThread(r2)).andReturn(t2);
        EasyMock.replay(wrapped, r1, r2);
        BasicThreadFactory factory = builder.wrappedFactory(wrapped).build();
        assertSame("Wrong thread 1", t1, factory.newThread(r1));
        assertTrue("No daemon thread", t1.isDaemon());
        assertSame("Wrong thread 2", t2, factory.newThread(r2));
View Full Code Here

    @Test
    public void testNewThreadPriority() {
        ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class);
        Runnable r = EasyMock.createMock(Runnable.class);
        Thread t = new Thread();
        EasyMock.expect(wrapped.newThread(r)).andReturn(t);
        EasyMock.replay(wrapped, r);
        final int priority = Thread.NORM_PRIORITY + 1;
        BasicThreadFactory factory = builder.wrappedFactory(wrapped).priority(
                priority).build();
        assertSame("Wrong thread", t, factory.newThread(r));
View Full Code Here

        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

        ? 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

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.