Don't create a new BigArrays instance for every call of `withCircuitBreaking`

Since the circuit breaking service doesn't actually change for
BigArrays, we can eagerly create a new instance only once and use that
for all further invocations of `withCircuitBreaking`.
This commit is contained in:
Lee Hinman 2015-04-24 16:06:33 -06:00
parent d164526d27
commit 240bcc3f08
1 changed files with 8 additions and 2 deletions

View File

@ -364,6 +364,7 @@ public class BigArrays {
final PageCacheRecycler recycler;
final CircuitBreakerService breakerService;
final boolean checkBreaker;
private final BigArrays circuitBreakingInstance;
@Inject
public BigArrays(PageCacheRecycler recycler, @Nullable final CircuitBreakerService breakerService) {
@ -375,6 +376,11 @@ public class BigArrays {
this.checkBreaker = checkBreaker;
this.recycler = recycler;
this.breakerService = breakerService;
if (checkBreaker) {
this.circuitBreakingInstance = this;
} else {
this.circuitBreakingInstance = new BigArrays(recycler, breakerService, true);
}
}
/**
@ -410,11 +416,11 @@ public class BigArrays {
}
/**
* Return a new instance of this BigArrays class with circuit breaking
* Return an instance of this BigArrays class with circuit breaking
* explicitly enabled, instead of only accounting enabled
*/
public BigArrays withCircuitBreaking() {
return new BigArrays(this.recycler, this.breakerService, true);
return this.circuitBreakingInstance;
}
private <T extends AbstractBigArray> T resizeInPlace(T array, long newSize) {