Forums Register Login

plz help, trying to read from a file...

+Pie Number of slices to send: Send
I want to write a Java program that reads from the logfile while it is being generated. What I understand from the logfile is, records of website traffic are added to the logfile as the website receives hits..

The website in question doe not receive any hits after end of the day.
I have written a program that analyses the logs at the end of the day i.e. when all the transacations are over and there are no new additions to the file, the program will take that file and process the data.
Now I want to modify it to make it real time.

i.e. instead of processing the logfile at the end of the day, I want my program to take a line from the log file as soon as it is added to it, process it, wait till next line is available, grab it as soon as it becomes available and so on till we reach the end of the day.

I have never done anything so complicated before, have been searching the net for quite a few days now but could not find any idea suitable to my needs.

I will be really grateful if I get any help in accomplishing this.
Thanks in advance.
Looking forward for inputs
+Pie Number of slices to send: Send
Tejaswini,
There is no way to get notified when the file is updated. You will have to poll (have a thread sleep for a while in a loop) to see if the file has been updated. You can keep track of the last line read and then only process the new lines.
+Pie Number of slices to send: Send
Assuming that you have a single point of call which writes to the log, you could do it by setting up an event when this api writes to the log file and having listeners that respond to these events. As posted earlier, it would be nice if the listeners have a low-priority thread that does the processing. That in turn would depend on the application and the technologies used therein.
It would certainly slow down ur app, so be sure to test the app for performance.

tx,
ram.
+Pie Number of slices to send: Send
Thanks for your inputs.
Please keep me posted if you find anything relevant to this in near future.

Teju
You get good luck from rubbing the belly of a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 735 times.
Similar Threads
How to Go to a new Line using RandomAccessFile
A Design Question
reading from a file in real time.
Starting the preparation SCBCD
File object can't find directory
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:50:29.