Essem
Essem

Reputation: 11

Issue with FileWriter

I'm running my java application on a windows 2008 server (64-bit) in the hotspot vm.

A few months ago I created a tool to assist in the detection of deadlocking in my application. For the past month or so, the only thing that has been giving me any problems is the writing to text files.

The main thread always seems to get stuck on the following line for what I would assume to be almost 5 seconds at a time. After a few seconds the application continues to run normally and without problems:

PrintWriter writer = new PrintWriter(new FileWriter(PATH + name + ".txt"));

Not sure what causes this, but any insight into the problem would be most appreciated. The files I'm writing are small and that is unlikely the issue (unless anyone has any objections).

If you need any more information, please let me know.

Upvotes: 0

Views: 638

Answers (2)

user207421
user207421

Reputation: 310850

Is PATH on a network drive? You could see almost any delay writing to a network file system. It's generally a very bad idea to do that with applications. They should generally write all their files locally and then post transactions to a server somehow.

Upvotes: 1

Peter Lawrey
Peter Lawrey

Reputation: 533442

When your file system gets overloaded, you can see delays with even the simplest of tasks. e.g. If I create a large file (multiple GB) and try to do a a simple disk access which is not cached it can wait seconds.

I would check your disk write cache is turned on and your disks are idle most of the time. ;)

Upvotes: 0

Related Questions