FileWriter 的问题
我正在热点虚拟机中的 Windows 2008 服务器(64 位)上运行我的 java 应用程序。
几个月前,我创建了一个工具来帮助检测应用程序中的死锁。在过去一个月左右的时间里,唯一给我带来任何问题的是写入文本文件。
主线程似乎总是卡在下一行,我认为每次大约 5 秒。几秒钟后,应用程序继续正常运行,没有问题:
PrintWriter writer = new PrintWriter(new FileWriter(PATH + name + ".txt"));
不确定是什么原因导致的,但如果能深入了解问题,我们将不胜感激。我正在编写的文件很小,这不太可能是问题(除非有人有任何反对意见)。
如果您需要更多信息,请告诉我。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PATH 是否位于网络驱动器上?您几乎可以看到写入网络文件系统的任何延迟。对于应用程序来说这样做通常是一个非常糟糕的主意。他们通常应该在本地写入所有文件,然后以某种方式将事务发布到服务器。
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.
当您的文件系统过载时,即使是最简单的任务也会出现延迟。例如,如果我创建一个大文件(多个 GB)并尝试执行未缓存的简单磁盘访问,则可能需要等待几秒钟。
我会检查您的磁盘写入缓存是否已打开,并且您的磁盘大部分时间都处于空闲状态。 ;)
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. ;)