Skip to content

Instantly share code, notes, and snippets.

@jhorstmann
Created October 28, 2016 20:02
Show Gist options
  • Save jhorstmann/9580b9987022760f859e800228ce0080 to your computer and use it in GitHub Desktop.
Save jhorstmann/9580b9987022760f859e800228ce0080 to your computer and use it in GitHub Desktop.
Investigating memory usage of exchange rate conversions in moneta
# same behaviour with LAZY
load.ECBCurrentRateProvider.type=NEVER
load.ECBHistoric90RateProvider.type=NEVER
load.ECBHistoricRateProvider.type=NEVER
load.IMFRateProvider.type=NEVER
# try to disable default conversions
conversion.default-chain=IDENT
Oct 28, 2016 10:00:03 PM org.javamoney.moneta.internal.loader.LoadRemoteDataLoaderService execute
INFO: The exchange rate with resourceId IMFHistoricRateProvider was started remotely
Oct 28, 2016 10:00:03 PM org.javamoney.moneta.internal.loader.LoadRemoteDataLoaderService execute
INFO: The exchange rate with resourceId ECBHistoric90RateProvider was started remotely
Oct 28, 2016 10:00:03 PM org.javamoney.moneta.internal.loader.LoadRemoteDataLoaderService execute
INFO: The exchange rate with resourceId IMFRateProvider was started remotely
Oct 28, 2016 10:00:03 PM org.javamoney.moneta.internal.loader.LoadRemoteDataLoaderService execute
INFO: The exchange rate with resourceId ECBCurrentRateProvider was started remotely
Oct 28, 2016 10:00:03 PM org.javamoney.moneta.internal.convert.ECBAbstractRateProvider newDataLoaded
INFO: Loaded ECBCurrentRateProvider exchange rates for days:1
Oct 28, 2016 10:00:03 PM org.javamoney.moneta.DefaultMonetaryContextFactory createMonetaryContextNonNullConfig
INFO: Using custom MathContext: precision=256, roundingMode=HALF_EVEN
EUR 1
Oct 28, 2016 10:00:03 PM org.javamoney.moneta.internal.convert.ECBAbstractRateProvider newDataLoaded
INFO: Loaded ECBHistoric90RateProvider exchange rates for days:63
Oct 28, 2016 10:00:08 PM org.javamoney.moneta.internal.convert.ECBAbstractRateProvider newDataLoaded
INFO: Loaded ECBHistoricRateProvider exchange rates for days:4358
import org.javamoney.moneta.Money;
import javax.money.MonetaryAmount;
import javax.money.convert.CurrencyConversion;
import javax.money.convert.MonetaryConversions;
import java.math.BigDecimal;
public class TestConversions {
public static void main(String[] args) throws InterruptedException {
CurrencyConversion toEuro = MonetaryConversions.getConversion("EUR");
MonetaryAmount oneEuroInEuro = toEuro.apply(Money.of(BigDecimal.ONE, "EUR"));
System.out.println(oneEuroInEuro);
// Wait a bit, then acquire a heap dump using eclipse memory analyzer
// See that ECBHistoricRateProvider is using > 70MB
while (true) {
Thread.sleep(1000);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment