Friday 25 April 2008

LOG kills

Never activates log in DEBUG mode. That kills memory and performance. Always use INFO. Debug should be used with AOP to trace execution only.

Wednesday 16 April 2008

Money money money, bug me honey


Money
int value;
String currency;

Money add(Money initial, Money toAdd) {
int value = initial.getValue() + dogAmount.getValue();
Money money = new AnimalMoney(value, initial.getCurrency())

return money;
}


Everything looks alright, but it's not.

Try to add money using these one :


Money cat = new AnimalMoney(5, "cat");
Money dog = new AnimalMoney(1, "dog");

Money deal = add(cat, dog);


You will obtain 6 values of cat. Does 5 cats plus 1 dog equals 6 cats. I think not.

Always think about the type of what you deal with. Remember your physics lectures when we calculate the result kind, like multiply hours by km per hour.

One solution can be to lower the accessibility of the inner elements. Money value and currency should not be manipulated outside its package. Outside package code must only use helper function to manipulate them.

Tuesday 15 April 2008

OutOfMemoryError Problem To Log

How appears a vicious OutOfMemoryError on 2/3 of the dev computer ?

The same JVM, the same sources, the same web server...

Everything is the same ! Everything ? Not the application config file nor the log4j config file.

Yep, OutOfMemory because of DEBUG level, others with INFO. Why ? Because of the fuck root handler the gives the DEBUG level for every API that use log4j, and so for the one that log the application database access. More than 1GB while we use only 300MB ordinary.

Becareful with logger. Always use root INFO and provides category for your application packages.