Slow readng tzdb.dat
Dr Heinz M. Kabutz
heinz at javaspecialists.eu
Wed Oct 9 18:00:04 UTC 2013
May I suggest rather:
try (
File file = new File(libDir, "tzdb.dat");
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis, 32000);
DataInputStream dis = new DataInputStream(bis);
) {
...
That way, the resources are closed in the reverse order in which they
are opened and an exception in the middle of the creation chain does not
prevent the earlier resources from being closed.
Regards
Heinz
--
Dr Heinz M. Kabutz (PhD CompSci)
Author of "The Java(tm) Specialists' Newsletter"
Oracle Java Champion 2005-2013
JavaOne Rock Star Speaker 2012
http://www.javaspecialists.eu
Tel: +30 69 75 595 262
Skype: kabutz
Salter, Thomas A wrote:
> I noticed recently that the JDK8 JVM was very slow starting on systems where the JRE is on a high-latency, remote file system. I tracked this down to the reading of tzdb.dat. In java/time/zone/TzdbZoneRulesProvider.java and sun/util/calendar/ZoneInfoFile.java the tzdb.dat file is read using a DataInputStream directly over a FileInputStream. Consequently there ends up being a large number of very small (often a single byte) read requests to the underlying O/S file system. This can be fixed trivially by adding a BufferedInputStream between the DataInputStream and the FileInputStream.
>
> Thus this:
> try (DataInputStream dis = new DataInputStream(
> new FileInputStream(new File(libDir, "tzdb.dat")))) {
> becomes:
> try (DataInputStream dis = new DataInputStream(
> new BufferedInputStream(
> new FileInputStream(new File(libDir, "tzdb.dat")), 32000))) {
>
>
>
> Tom Salter | Software Engineer | Java & Middleware Development
> Unisys | 2476 Swedesford Road | Malvern, PA 19355 | 610-648-2568 | N385-2568
>
>
>
>
More information about the core-libs-dev
mailing list