How to tail a file using a NIO selector, in other words, as lines are added to the file a channel is selected so you can read the lines?
Asked Answered
A

2

0

Because you cannot redirect GC logs I am left with the option to redirect it to a file with -Xloggc and then get the contents of this file inside my selector through a file channel of some kind. Basically as lines are being added to my file, the selector is being triggered to read them. That way I can get the GC logs programmatically. Is it possible to do that using NIO?

Abshier answered 24/3, 2012 at 22:19 Comment(0)
M
0

No. FileChannel does not extend SelectableChannel so you can't select with it, and even in C where you can, select() doesn't deliver readable events when the file is extended (it delivers them every time you select, as the file is always readable).

Maugham answered 25/3, 2012 at 1:18 Comment(0)
G
0

Given GC logs are buffered, I wouldn't worry about a bit of latency. You can just poll the file length periodically and read the data added each time. You can do this in IO, NIO or NIO2.

Gooseflesh answered 25/3, 2012 at 8:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.