quarta-feira, abril 23, 2008

Cliff Click's NonBlocking HashTable

Cliff Click has made available his new brainchild, the NonBlocking HashTable.

He claims that it is faster than java.util.concurrent.ConcurrentHashMap.

Check: http://blogs.azulsystems.com/cliff/2007/04/nonblocking_has.html

http://sourceforge.net/projects/high-scale-lib

DecimalFormat, SimpleDateFormat - Threading Issues

The classes java.text.DecimalFormat and java.text.SimpleDateFormat are very useful, but Sun's implementation is not thread-safe. It means that if you want to have a static instance of any of these classes in your EJB, Servlet or JSP page, you can have sporadic problems with incorrect formatting.
You'll need to use a ThreadLocal, or use a local object.
ThreadLocal sample usage:

private static ThreadLocal defaultCurrencyFormat  = new ThreadLocal() {
protected synchronized Format initialValue() {
return new DecimalFormat ("0.00",
new DecimalFormatSymbols (new Locale ("pt", "BR")));
}
};

...

String s = defaultCurrencyFormat.get().format (123.45);

You'll need to use an additional "get".