Re: Tomcat can't 'see' new files
Dave Miller <nonregistered@coldrain.net> writes:
Michael Jung wrote:
HightowerC <chris.hightower@gmail.com> writes:
I have the same problem (which doesn't really make it more on-topic:-)
when I generate temporary files. Tomcat doesn't serve them. I haven't
made any elaborate time measurements, but I can contribute that it
happens on Linux (both client and server) and I looked at the files
with ls and cat during the problem time and I tried various browsers;
I'm pretty sure it's a Tomcat problem.
ls is merely listing the directory and cat will take whatever is on
disk at that point in time. Neither tell you whether the file is
readable by Tomcat or another app.
I don't see the difference between cat and "another app". It was a
new file and I checked the permissions; they were okay.
If you can open or use the file in its native app and Tomcat still
won't serve it, it's a container problem. Otherwise, it would seem
unlikely that Tomcat is the culprit.
What is a file's native app? Do you ask, whether I can reopen the
file in the same thread, where I closed it?
This is the code:
try {
long t = System.currentTimeMillis();
Writer w = new BufferedWriter(new FileWriter(myDir + t + ".html"));
String f = ...
w.write(f);
w.flush();
w.close();
}
catch (IOException e) {
e.printStackTrace();
}
What I will do then is ls in myDir and paste the <t>.html into a
browser -> not served. (BTW, repeated calls to the above will create
new temporary files. The first one is still not served.)
What's more likely is that the stream writing the file is not closing
properly and Tomcat is respecting its lock.
With the code above that would imply a bug in java file handling. (Or
do I have to keep a handle on the FileWriter and close it explicitely
as well? That's counter intuitive.) I haven't experienced the problem
outside of Tomcat though, i.e. usually opening the file from another
process or thread within the process. In fact, I have written a small
http server because of this exact problem (and it works). It doesn't
serve "jsp" yet though:-(
Michael