Wait until file updated
Hi,
I have to read text (lines) from several files, and after that, I have to wait until new information is written to the file (as log files). The new data should be processed as it comes (in real time).
how can I wait until the new information is written?
The goal is not to make a sleep() of every thread.
Thanks
[346 byte] By [
txatia] at [2007-11-27 7:35:30]

# 1
Well the goal is to read the file when it has been updated actually. I can't think of any way of avoiding Thread.sleep() until JDK 1.7 comes out. Unless the process doing the writing is in the same JVM, in which case it could notify the waiting thread(s).
ejpa at 2007-7-12 19:16:06 >

# 2
The -f option of the Unix command tail works so that the file is kept on being read even after an end-of-file. The read operation will block until new data arrives, so there is no need to poll (keep in trying actively). Is this scenario feasible in Java?
# 4
The read process is in Java, but the other is a third party program out of my control.The goal is to behave like "tail -f" Unix command.The problem is that I have several files to read from, and sleep/wake all threads could be very heavy. Am I correct?
txatia at 2007-7-12 19:16:06 >

# 5
The question immediately arises 'heavy compared to what?'
If you can't get the other process to do a lock, or signal you some other way, you will have to sleep, just like tail -f does, regardless whether light, heavy, black, white, ... There is no other solution , at least not before JDK 1.7 comes out.
ejpa at 2007-7-12 19:16:06 >
