Skip to content

Commit

Permalink
Merge pull request Netflix#1113 from mattrjacobs/backport-closeable-t…
Browse files Browse the repository at this point in the history
…o-14x

Backport Netflix#1111 to 1.4.x
  • Loading branch information
mattrjacobs committed Feb 29, 2016
2 parents ced9f74 + b6fa398 commit b3d74a5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.netflix.hystrix.strategy.concurrency;

import java.io.Closeable;
import java.util.concurrent.ConcurrentHashMap;

import com.netflix.hystrix.HystrixCollapser;
Expand Down Expand Up @@ -60,7 +61,7 @@
* <p>
* <b>NOTE:</b> If <code>initializeContext()</code> is called then <code>shutdown()</code> must also be called or a memory leak will occur.
*/
public class HystrixRequestContext {
public class HystrixRequestContext implements Closeable {

/*
* ThreadLocal on each thread will hold the HystrixRequestVariableState.
Expand Down Expand Up @@ -142,4 +143,16 @@ public void shutdown() {
state = null;
}
}
}

/**
* Shutdown {@link HystrixRequestVariableDefault} objects in this context.
* <p>
* <b>NOTE: This must be called if <code>initializeContext()</code> was called or a memory leak will occur.</b>
*
* This method invokes <code>shutdown()</code>
*/
public void close() {
shutdown();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public void testRequestVariableLifecycle1() throws Exception {
System.out.println("tasks in test: " + timer.tasks);

// simulate request lifecycle
requestContext.shutdown();
requestContext.close();

System.out.println("timer.tasks.size() B: " + timer.tasks.size());

Expand Down Expand Up @@ -454,7 +454,7 @@ public void run() {
}

// simulate request lifecycle
requestContext.shutdown();
requestContext.close();

HystrixRequestVariableHolder<RequestCollapser<?, ?, ?>> rv = RequestCollapserFactory.getRequestVariable(new TestRequestCollapser(timer, 1).getCollapserKey().name());

Expand Down

0 comments on commit b3d74a5

Please sign in to comment.