Java reads log files in real time

Java reads log files in real time … here is a solution to the problem.

Java reads log files in real time

I’m writing a cod4 server controller in Java (I know there are very good server controllers out there, but I want to learn from them). Now I want to take a specific action based on the entries in the log file, which is frequently updated by the cod and the file can become very large. Now, how can I efficiently read only the changed parts of the file every second or so?

Or is there a way to send everything that has changed in the log file to Java in real time? (I read a little about plumbing). The server runs on Linux. There is no need to save the log file in the same location because everything should be through Java and I can save it with it.


delay of about 1 second or 2 seconds is acceptable, but not much longer.


Maybe you can do the “tail -f logfile.txt” subprocess and monitor the output stream?

Related Problems and Solutions