开发者

What can cause this Java behaviour?

My project generates some text/binary files. If I run it normally, some files will have a pretty low size ( which indicates something went wrong ). If I run it from debug mode ( stepping through code ), the files will be generated correctly.

What can cause this behaviour? I'm pretty sure I don't have any unclosed files.

EDIT: I've gone through the code in a more focused way, and I've found the problem. At one point in time, the files ge开发者_如何学Got compressed, and this explains the decrease in size. I'm stupid :) A moderator can close this question if he sees fit.


Try adding:

System.gc();
try { Thread.sleep(4000); } catch (Exception e) {}
System.gc();

...at the end of your program. If the problem goes away then you did forget to close() a file. The above code is no solution, it is a hacky attempt to increase the likelyhood finalizers will run.


Is your code multithreaded? Are you trying to read something that you haven't given another thread a chance to finish constructing, which doesn't manifest when you're stepping through it?


Do you call some kind of "read" method, to read from a file, for example, and assume that you will always get back the number of bytes that you request?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜