• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Tejaswini Shirkhedkar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36446
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tejaswini Shirkhedkar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your inputs.
Please keep me posted if you find anything relevant to this in near future.

Teju
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!