Skip to content

Add utility function to check if an executor is direct or not#143

Open
krka wants to merge 1 commit intospotify:masterfrom
krka:krka/directexecutor
Open

Add utility function to check if an executor is direct or not#143
krka wants to merge 1 commit intospotify:masterfrom
krka:krka/directexecutor

Conversation

@krka
Copy link
Contributor

@krka krka commented Sep 26, 2019

Don't move futures to different executor if it's a direct executor

@krka krka force-pushed the krka/directexecutor branch 3 times, most recently from d92ec07 to e4f772b Compare September 26, 2019 18:58
Don't move futures to different executor if it's a direct executor
@krka krka force-pushed the krka/directexecutor branch from e4f772b to c569754 Compare September 26, 2019 19:07
@coveralls
Copy link

Coverage Status

Coverage remained the same at ?% when pulling c569754 on krka:krka/directexecutor into b7395b3 on spotify:master.

int maxSetLength) {
this.address = address;
this.executor = executor;
this.isDirectExecutor = executor == null || Utils.isDirectExecutor(executor);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicking here, but given isDirectExecutor really meaning "is a direct executor or null", how about rather naming it something like "wrapWithExecutor"? (I'm terrible at naming so I'm sure an even better name would be available)

Copy link
Member

Choose a reason for hiding this comment

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

Sure, that's a good idea

// 1) It is a direct executor, so runnableWithThread.thread will be set to the current thread.
// We will correctly return true
// 2) It is not a direct executor and runnableWithThread.thread is still null when we check
// it.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicking: wrong indentation

Copy link
Member

Choose a reason for hiding this comment

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

Oops


return runnableWithThread.thread == Thread.currentThread();
} catch (Exception e) {
// If the executor throws any exception, it can not be a direct executor
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this as safe assumption? Looking at the Guava DirectExecutorService, it can throw exceptions here, but only if the executor is shutting down, which is probably fine either way. But, would we want to assume other direct executors would behave the same way?

Copy link
Member

Choose a reason for hiding this comment

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

No, probably not a safe assumption. It depends a bit on what the function is used for. If it's only for optimization purposes and sanity checks it may still be good enough

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments