-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add utility function to check if an executor is direct or not #143
base: master
Are you sure you want to change the base?
Conversation
d92ec07
to
e4f772b
Compare
Don't move futures to different executor if it's a direct executor
e4f772b
to
c569754
Compare
@@ -194,6 +195,7 @@ private DefaultRawMemcacheClient( | |||
int maxSetLength) { | |||
this.address = address; | |||
this.executor = executor; | |||
this.isDirectExecutor = executor == null || Utils.isDirectExecutor(executor); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicking: wrong indentation
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Don't move futures to different executor if it's a direct executor