类java.util.concurrent.AbstractExecutorService源码实例Demo

下面列出了怎么用java.util.concurrent.AbstractExecutorService的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: vespa   文件: JobRunnerTest.java
private static ExecutorService phasedExecutor(Phaser phaser) {
    return new AbstractExecutorService() {
        final ExecutorService delegate = Executors.newFixedThreadPool(32);
        @Override public void shutdown() { delegate.shutdown(); }
        @Override public List<Runnable> shutdownNow() { return delegate.shutdownNow(); }
        @Override public boolean isShutdown() { return delegate.isShutdown(); }
        @Override public boolean isTerminated() { return delegate.isTerminated(); }
        @Override public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { return delegate.awaitTermination(timeout, unit); }
        @Override public void execute(Runnable command) {
            phaser.register();
            delegate.execute(() -> {
                command.run();
                phaser.arriveAndDeregister();
            });
        }
    };
}
 
@Override
protected ExecutorService getDefaultExecutorService() {
    if (isMultiThreaded()) {
        return super.getDefaultExecutorService();
    }
    return new AbstractExecutorService() {

        boolean terminated;

        public void shutdown() {
            terminated = true;
        }

        public List<Runnable> shutdownNow() {
            shutdown();
            return null;
        }

        public boolean isShutdown() {
            return terminated;
        }

        public boolean isTerminated() {
            return terminated;
        }

        public boolean awaitTermination(long l, TimeUnit timeUnit) throws InterruptedException {
            shutdown();
            return terminated;
        }

        public void execute(Runnable runnable) {
            runnable.run();
        }
    };
}
 
private static Executor wrapExecutor(Executor executor) {
    if (executor instanceof TaskExecutorService && executor instanceof AbstractExecutorService) {
        return executor;
    } else {
        return new GenericExecutorWrapper(executor);
    }
}
 
源代码4 项目: okta-sdk-appauth-android   文件: TestUtils.java
public static ExecutorService buildSyncynchronesExecutorService() {
    return new AbstractExecutorService() {
        @Override
        public void shutdown() {

        }

        @Override
        public List<Runnable> shutdownNow() {
            return null;
        }

        @Override
        public boolean isShutdown() {
            return false;
        }

        @Override
        public boolean isTerminated() {
            return false;
        }

        @Override
        public boolean awaitTermination(long l, TimeUnit timeUnit) throws InterruptedException {
            return false;
        }

        @Override
        public void execute(Runnable runnable) {
            runnable.run();
        }
    };
}
 
源代码5 项目: vespa   文件: JobRunnerTest.java
public static ExecutorService inThreadExecutor() {
    return new AbstractExecutorService() {
        final AtomicBoolean shutDown = new AtomicBoolean(false);
        @Override public void shutdown() { shutDown.set(true); }
        @Override public List<Runnable> shutdownNow() { shutDown.set(true); return Collections.emptyList(); }
        @Override public boolean isShutdown() { return shutDown.get(); }
        @Override public boolean isTerminated() { return shutDown.get(); }
        @Override public boolean awaitTermination(long timeout, TimeUnit unit) { return true; }
        @Override public void execute(Runnable command) { command.run(); }
    };
}
 
源代码6 项目: spotbugs   文件: Ideas_2010_11_23.java
@ExpectWarning("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")

    public  void test(AbstractExecutorService service, Callable<T> callable, Runnable runnable, T value) {
        service.submit(callable);
        service.submit(runnable);
        service.submit(runnable, value);

    }
 
源代码7 项目: DroidDLNA   文件: MockUpnpServiceConfiguration.java
@Override
protected ExecutorService getDefaultExecutorService() {
    if (isMultiThreaded()) {
        return super.getDefaultExecutorService();
    }
    return new AbstractExecutorService() {

        boolean terminated;

        public void shutdown() {
            terminated = true;
        }

        public List<Runnable> shutdownNow() {
            shutdown();
            return null;
        }

        public boolean isShutdown() {
            return terminated;
        }

        public boolean isTerminated() {
            return terminated;
        }

        public boolean awaitTermination(long l, TimeUnit timeUnit) throws InterruptedException {
            shutdown();
            return terminated;
        }

        public void execute(Runnable runnable) {
            runnable.run();
        }
    };
}
 
源代码8 项目: yelp-android   文件: AsyncTestUtils.java
/**
 * Create an {@link ExecutorService} which runs jobs in main thread.
 */
public static ExecutorService newSynchronousExecutorService() {
    return new AbstractExecutorService() {
        @Override
        public void execute(Runnable command) {
            command.run();
        }

        @Override
        public void shutdown() {
            throw new UnsupportedOperationException();
        }

        @Override
        public List<Runnable> shutdownNow() {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean isShutdown() {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean isTerminated() {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
            throw new UnsupportedOperationException();
        }
    };
}
 
源代码9 项目: xian   文件: LeaderSelector.java
private static ExecutorService wrapExecutor(final Executor executor)
{
    return new AbstractExecutorService()
    {
        private volatile boolean isShutdown = false;
        private volatile boolean isTerminated = false;

        @Override
        public void shutdown()
        {
            isShutdown = true;
        }

        @Override
        public List<Runnable> shutdownNow()
        {
            return Lists.newArrayList();
        }

        @Override
        public boolean isShutdown()
        {
            return isShutdown;
        }

        @Override
        public boolean isTerminated()
        {
            return isTerminated;
        }

        @Override
        public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
        {
            throw new UnsupportedOperationException();
        }

        @Override
        public void execute(Runnable command)
        {
            try
            {
                executor.execute(command);
            }
            finally
            {
                isShutdown = true;
                isTerminated = true;
            }
        }
    };
}
 
源代码10 项目: cyberduck   文件: ExecutorServiceThreadPool.java
public ExecutorServiceThreadPool(final AbstractExecutorService pool) {
    this.pool = pool;
}
 
源代码11 项目: cyberduck   文件: ExecutorServiceThreadPool.java
@Override
public AbstractExecutorService executor() {
    return pool;
}
 
源代码12 项目: spotbugs   文件: CheckJDKAnnotations.java
Future falsePositive(AbstractExecutorService e, Runnable r) {
    return e.submit(r, null);
}
 
源代码13 项目: reactor-core   文件: ExecutorSchedulerTest.java
@Test
public void failingExecutorServiceIsNotTerminated() {
	AtomicInteger count = new AtomicInteger();
	final IllegalStateException boom = new IllegalStateException("boom");
	ExecutorService service = new AbstractExecutorService() {

		boolean shutdown;

		@Override
		public void shutdown() {
			shutdown = true;
		}

		@NotNull
		@Override
		public List<Runnable> shutdownNow() {
			return Collections.emptyList();
		}

		@Override
		public boolean isShutdown() {
			return shutdown;
		}

		@Override
		public boolean isTerminated() {
			return shutdown;
		}

		@Override
		public boolean awaitTermination(long timeout, @NotNull TimeUnit unit)
				throws InterruptedException {
			return false;
		}

		@Override
		public void execute(@NotNull Runnable command) {
			if (count.incrementAndGet() % 2 == 0)
				throw boom;
		}
	};
	ExecutorScheduler scheduler = new ExecutorScheduler(service, false);

	assertThatCode(() -> scheduler.schedule(() -> {}))
			.as("initial-no rejection")
			.doesNotThrowAnyException();

	assertThatExceptionOfType(RejectedExecutionException.class)
			.as("second-transient rejection")
			.isThrownBy(() -> scheduler.schedule(() -> {}))
			.withCause(boom);

	assertThatCode(() -> scheduler.schedule(() -> {}))
			.as("third-no rejection")
			.doesNotThrowAnyException();

	assertThat(count.get()).isEqualTo(3);
}
 
源代码14 项目: reactor-core   文件: ExecutorSchedulerTest.java
@Test
public void failingAndShutDownExecutorServiceIsTerminated() {
	final IllegalStateException boom = new IllegalStateException("boom");
	ExecutorService service = new AbstractExecutorService() {

		boolean shutdown;

		@Override
		public void shutdown() {
			shutdown = true;
		}

		@NotNull
		@Override
		public List<Runnable> shutdownNow() {
			return Collections.emptyList();
		}

		@Override
		public boolean isShutdown() {
			return shutdown;
		}

		@Override
		public boolean isTerminated() {
			return shutdown;
		}

		@Override
		public boolean awaitTermination(long timeout, @NotNull TimeUnit unit)
				throws InterruptedException {
			return false;
		}

		@Override
		public void execute(@NotNull Runnable command) {
			if (shutdown) throw boom;
			shutdown = true;
		}
	};
	ExecutorScheduler scheduler = new ExecutorScheduler(service, false);

	assertThatCode(() -> scheduler.schedule(() -> {}))
			.as("initial-no rejection")
			.doesNotThrowAnyException();

	assertThatExceptionOfType(RejectedExecutionException.class)
			.as("second-transient rejection")
			.isThrownBy(() -> scheduler.schedule(() -> {}))
			.withCause(boom);

	assertThatExceptionOfType(RejectedExecutionException.class)
			.as("third scheduler terminated rejection")
			.isThrownBy(() -> scheduler.schedule(() -> {}))
			.isSameAs(Exceptions.failWithRejected())
			.withNoCause();
}
 
源代码15 项目: curator   文件: LeaderSelector.java
private static ExecutorService wrapExecutor(final Executor executor)
{
    return new AbstractExecutorService()
    {
        private volatile boolean isShutdown = false;
        private volatile boolean isTerminated = false;

        @Override
        public void shutdown()
        {
            isShutdown = true;
        }

        @Override
        public List<Runnable> shutdownNow()
        {
            return Lists.newArrayList();
        }

        @Override
        public boolean isShutdown()
        {
            return isShutdown;
        }

        @Override
        public boolean isTerminated()
        {
            return isTerminated;
        }

        @Override
        public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
        {
            throw new UnsupportedOperationException();
        }

        @Override
        public void execute(Runnable command)
        {
            try
            {
                executor.execute(command);
            }
            finally
            {
                isShutdown = true;
                isTerminated = true;
            }
        }
    };
}
 
源代码16 项目: cyberduck   文件: ThreadPool.java
AbstractExecutorService executor(); 
 类所在包
 同包方法