Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,51 +59,67 @@ private void checkQueue(int numberOfTasks) {

@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException {
checkQueue(tasks.size());
return super.invokeAll(tasks);
synchronized (this) {
checkQueue(tasks.size());
return super.invokeAll(tasks);
}
}

@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
throws InterruptedException {
checkQueue(tasks.size());
return super.invokeAll(tasks, timeout, unit);
synchronized (this) {
checkQueue(tasks.size());
return super.invokeAll(tasks, timeout, unit);
}
}

@Override
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException {
checkQueue(tasks.size());
return super.invokeAny(tasks);
synchronized (this) {
checkQueue(tasks.size());
return super.invokeAny(tasks);
}
}

@Override
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
checkQueue(tasks.size());
return super.invokeAny(tasks, timeout, unit);
synchronized (this) {
checkQueue(tasks.size());
return super.invokeAny(tasks, timeout, unit);
}
}

@Override
public void execute(Runnable command) {
checkQueue(1);
super.execute(command);
synchronized (this) {
checkQueue(1);
super.execute(command);
}
}

@Override
public <T> Future<T> submit(Callable<T> task) {
checkQueue(1);
return super.submit(task);
synchronized (this) {
checkQueue(1);
return super.submit(task);
}
}

@Override
public Future<?> submit(Runnable task) {
checkQueue(1);
return super.submit(task);
synchronized (this) {
checkQueue(1);
return super.submit(task);
}
}

@Override
public <T> Future<T> submit(Runnable task, T result) {
checkQueue(1);
return super.submit(task, result);
synchronized (this) {
checkQueue(1);
return super.submit(task, result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,78 +59,102 @@ protected ListeningExecutorService delegate() {

@Override
public ListenableScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
this.checkQueue(1);
return this.thread.schedule(command, delay, unit);
synchronized (this) {
this.checkQueue(1);
return this.thread.schedule(command, delay, unit);
}
}

@Override
public <V> ListenableScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
this.checkQueue(1);
return this.thread.schedule(callable, delay, unit);
synchronized (this) {
this.checkQueue(1);
return this.thread.schedule(callable, delay, unit);
}
}

@Override
public ListenableScheduledFuture<?> scheduleAtFixedRate(Runnable command,
long initialDelay, long period, TimeUnit unit) {
this.checkQueue(1);
return this.thread.scheduleAtFixedRate(command, initialDelay, period, unit);
synchronized (this) {
this.checkQueue(1);
return this.thread.scheduleAtFixedRate(command, initialDelay, period, unit);
}
}

@Override
public ListenableScheduledFuture<?> scheduleWithFixedDelay(Runnable command,
long initialDelay, long delay, TimeUnit unit) {
this.checkQueue(1);
return this.thread.scheduleAtFixedRate(command, initialDelay, delay, unit);
synchronized (this) {
this.checkQueue(1);
return this.thread.scheduleAtFixedRate(command, initialDelay, delay, unit);
}
}

@Override
public <T> ListenableFuture<T> submit(Callable<T> task) {
this.checkQueue(1);
return super.submit(task);
synchronized (this) {
this.checkQueue(1);
return super.submit(task);
}
}

@Override
public ListenableFuture<?> submit(Runnable task) {
this.checkQueue(1);
return super.submit(task);
synchronized (this) {
this.checkQueue(1);
return super.submit(task);
}
}

@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException {
this.checkQueue(tasks.size());
return super.invokeAll(tasks);
synchronized (this) {
this.checkQueue(tasks.size());
return super.invokeAll(tasks);
}
}

@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks,
long timeout, TimeUnit unit) throws InterruptedException {
this.checkQueue(tasks.size());
return super.invokeAll(tasks, timeout, unit);
synchronized (this) {
this.checkQueue(tasks.size());
return super.invokeAll(tasks, timeout, unit);
}
}

@Override
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException {
this.checkQueue(tasks.size());
return super.invokeAny(tasks);
synchronized (this) {
this.checkQueue(tasks.size());
return super.invokeAny(tasks);
}
}

@Override
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout,
TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
this.checkQueue(tasks.size());
return super.invokeAny(tasks, timeout, unit);
synchronized (this) {
this.checkQueue(tasks.size());
return super.invokeAny(tasks, timeout, unit);
}
}

@Override
public <T> ListenableFuture<T> submit(Runnable task, T result) {
this.checkQueue(1);
return super.submit(task, result);
synchronized (this) {
this.checkQueue(1);
return super.submit(task, result);
}
}

@Override
public void execute(Runnable command) {
this.checkQueue(1);
super.execute(command);
synchronized (this) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a style note..... you can push synchronized to the method signature

this.checkQueue(1);
super.execute(command);
}
}

private void checkQueue(int numberOfTasks) {
Expand Down