java.util.concurrent.AbstractExecutorService Java Examples

The following examples show how to use java.util.concurrent.AbstractExecutorService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: vespa   Author: vespa-engine   File: JobRunnerTest.java    License: Apache License 2.0 6 votes vote down vote up
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();
            });
        }
    };
}
 
Example #2
Source Project: TVRemoteIME   Author: kingthy   File: MockUpnpServiceConfiguration.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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();
        }
    };
}
 
Example #3
Source Project: tascalate-concurrent   Author: vsilaev   File: TaskExecutorCompletionService.java    License: Apache License 2.0 5 votes vote down vote up
private static Executor wrapExecutor(Executor executor) {
    if (executor instanceof TaskExecutorService && executor instanceof AbstractExecutorService) {
        return executor;
    } else {
        return new GenericExecutorWrapper(executor);
    }
}
 
Example #4
Source Project: okta-sdk-appauth-android   Author: okta   File: TestUtils.java    License: Apache License 2.0 5 votes vote down vote up
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();
        }
    };
}
 
Example #5
Source Project: vespa   Author: vespa-engine   File: JobRunnerTest.java    License: Apache License 2.0 5 votes vote down vote up
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(); }
    };
}
 
Example #6
Source Project: spotbugs   Author: spotbugs   File: Ideas_2010_11_23.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@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);

    }
 
Example #7
Source Project: DroidDLNA   Author: offbye   File: MockUpnpServiceConfiguration.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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();
        }
    };
}
 
Example #8
Source Project: yelp-android   Author: Yelp   File: AsyncTestUtils.java    License: MIT License 5 votes vote down vote up
/**
 * 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();
        }
    };
}
 
Example #9
Source Project: xian   Author: xiancloud   File: LeaderSelector.java    License: Apache License 2.0 4 votes vote down vote up
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;
            }
        }
    };
}
 
Example #10
Source Project: cyberduck   Author: iterate-ch   File: ExecutorServiceThreadPool.java    License: GNU General Public License v3.0 4 votes vote down vote up
public ExecutorServiceThreadPool(final AbstractExecutorService pool) {
    this.pool = pool;
}
 
Example #11
Source Project: cyberduck   Author: iterate-ch   File: ExecutorServiceThreadPool.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public AbstractExecutorService executor() {
    return pool;
}
 
Example #12
Source Project: spotbugs   Author: spotbugs   File: CheckJDKAnnotations.java    License: GNU Lesser General Public License v2.1 4 votes vote down vote up
Future falsePositive(AbstractExecutorService e, Runnable r) {
    return e.submit(r, null);
}
 
Example #13
Source Project: reactor-core   Author: reactor   File: ExecutorSchedulerTest.java    License: Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example #14
Source Project: reactor-core   Author: reactor   File: ExecutorSchedulerTest.java    License: Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example #15
Source Project: curator   Author: apache   File: LeaderSelector.java    License: Apache License 2.0 4 votes vote down vote up
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;
            }
        }
    };
}
 
Example #16
Source Project: cyberduck   Author: iterate-ch   File: ThreadPool.java    License: GNU General Public License v3.0 votes vote down vote up
AbstractExecutorService executor();