Skip to content

Commit

Permalink
Merge pull request #137 from benjchristensen/CurrentThreadExecutingCo…
Browse files Browse the repository at this point in the history
…mmand-scope

Limit scope of CurrentThreadExecutingCommand
  • Loading branch information
benjchristensen committed Apr 4, 2013
2 parents c31197b + a1ae5b2 commit 8251bed
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -627,25 +627,27 @@ public ExecutionResult getExecutionResult() {
}
}

// store the command that is being run
Hystrix.startCurrentThreadExecutingCommand(getCommandKey());
try {
// store the command that is being run
Hystrix.startCurrentThreadExecutingCommand(getCommandKey());

// execute outside of future so that fireAndForget will still work (ie. someone calls queue() but not get()) and so that multiple requests can be deduped through request caching
R r = executeCommand();
r = executionHook.onComplete(this, r);
value.set(r);
// execute outside of future so that fireAndForget will still work (ie. someone calls queue() but not get()) and so that multiple requests can be deduped through request caching
R r = executeCommand();
r = executionHook.onComplete(this, r);
value.set(r);

return responseFuture;
return responseFuture;
} finally {
// pop the command that is being run
Hystrix.endCurrentThreadExecutingCommand();
}

} finally {
// mark that we're completed
executionCompleted.countDown();
// release the semaphore
executionSemaphore.release();

// pop the command that is being run
Hystrix.endCurrentThreadExecutingCommand();

/* execution time on queue via semaphore */
recordTotalExecutionTime(invocationStartTime.get());
}
Expand Down Expand Up @@ -682,9 +684,6 @@ public R call() throws Exception {
// execution hook
executionHook.onThreadStart(_this);

// store the command that is being run
Hystrix.startCurrentThreadExecutingCommand(getCommandKey());

// count the active thread
threadPool.markThreadExecution();

Expand Down Expand Up @@ -714,9 +713,17 @@ public R call() throws Exception {
return null;
}

// execute the command
R r = executeCommand();
return executionHook.onComplete(_this, r);
try {
// store the command that is being run
Hystrix.startCurrentThreadExecutingCommand(getCommandKey());

// execute the command
R r = executeCommand();
return executionHook.onComplete(_this, r);
} finally {
// pop this off the thread now that it's done
Hystrix.endCurrentThreadExecutingCommand();
}
} catch (Exception e) {
if (!isCommandTimedOut.get()) {
// count (if we didn't timeout) that we are throwing an exception and re-throw it
Expand All @@ -725,8 +732,6 @@ public R call() throws Exception {
throw e;
} finally {
threadPool.markThreadCompletion();
// pop this off the thread now that it's done
Hystrix.endCurrentThreadExecutingCommand();

try {
executionHook.onThreadComplete(_this);
Expand Down

0 comments on commit 8251bed

Please sign in to comment.