The DecimalFormat class is not synchronized and cannot be shared between threads.
Paulo ----- Original Message ----- From: "Feng Dihai" <[email protected]> To: <[email protected]> Sent: Wednesday, December 24, 2008 2:34 AM Subject: [iText-questions] Performance improvement forByteBuffer.formatDouble(double, ByteBuffer) in HIGH_PRECISION mode In our case, it is important and necessary to output all floating point numbers in higer precision with 6 decimal digits. But I noticed that in ByteBuffer.formatDouble(double, ByteBuffer), a new instance of DecimalFormat is created at each call of the method which will causes a great performance loss. Just defining a shared instance of DecimlaFormat instead as a static field of ByteBuffer, we've got a double speed up. Here below is my suggestion on how to modify ByteBuffer: private static final DecimalFormat dn = new DecimalFormat("0.######", dfs); public static String formatDouble(double d, ByteBuffer buf) { if (HIGH_PRECISION) { // DecimalFormat dn = new DecimalFormat("0.######", dfs); String sform = dn.format(d); if (buf == null) return sform; else { buf.append(sform); return null; } } ... } ------------------------------------------------------------------------------ _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.1t3xt.com/docs/book.php
