Closed PetrToman closed 12 years ago
Okay, you really can't rename an EGB file once its been opened. Due to a "bug" in Java... once you open a binary file for high-speed (nio) access there is no way to ever close it, until Java exits. I will just display a message box stating it can't be renamed, once the file is in that state.
Running something like EncogEGBFile.getFc().close()
in EncogDocumentOperations.java before renaming didn't work?
Yeah it is a known bug in Java. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4715154
Sun actually does not consider it a bug, once you open a file in high-performance mode, that is it... the file stays open.
Thanks. There is a workaround mentioned in the bug report ("calling System.gc sometimes works"). I tried running the 1st example and it works for me after adding 3 lines:
bb = null; fc = null; System.gc();
I guess it should work for renaming the same. If so, it would be better to try to rename the file and just show an error message upon a failure.
Nice, that works well! I just checked in a change to both core/workbench to address. You can also delete EGB files too that have been open'd
It still seems a bit touchy. You can open/close a EGB file(double click) and it is fine. But the System.gc does not seem to always do the trick, like if the analyst had opened the EGB file, despite the fact that close/gc is called.
Its too bad this is so complex in Java... its so easy C++, not sure why they can't do the same.
I believe it's a) crucial to set variable=null before calling System.gc(), i.e. calling close() is not enough, b) System.gc() may not always work immediately. But this is the best that can be done now (and the underlying issue may be fixed some day).
I also believe this si not primarily a Java issue, but rather C/C++ :-) Forcing gc is just a workaround. Most likely, there is a flaw in unmapping a memory-mapped file in the Java runtime (as noted in one comment in the bug report you mentioned).
PS: I'd still suggest to rename "Properties" to "Rename" the pop menu item.
okay the rename makes sense, just checked that in.