It make JFR Event Streaming asynchronously with try-catch-resources more understandable
Erik Gahlin
erik.gahlin at oracle.com
Sun Feb 16 14:29:46 UTC 2020
Hi Chihiro,
Thanks for providing feedback.
When the RecordingStream is closed the underlying recording is stopped/closed, so no more data will be produced from that point on. Events are read in batches from disk, once every second, and a check if the stream is closed is done once per batch. One benefit with this behavior is that the application will get all the information in that window. For example, if you subscribe to a periodic event like ThreadAllocationStatistic you will get events for all threads.
We did consider to block in the close method until a batch has been sent out, but it could lead to applications blocking for an unreasonable amount time, for example if I/O is carried out in the callback.
Could you describe the use case when the stream not being stopped immediately is an issue? What problem does it cause?
Thanks
Erik
> On 16 Feb 2020, at 13:29, Chihiro Ito <chiroito107 at gmail.com> wrote:
>
> Hi,
>
> I tried to use JFR Event Streaming asynchronously. When I use it with
> try-catch-resource as the following code [1], It doesn't work. However, It
> seems normal behavior.
> This reason is that RecordingStream is auto closed. I think when it is
> called the close method, JFR and JFR Event Streaming should be stoped. But
> It is difficult for the user to aware of why it doesn't work.
> Why don't we output the log message for the async user as following [2].
>
> What do you think, everyone?
>
> I already implemented this and it seems fine.
>
> [1]
> public class JfrEventStreamingInProcessAsync {
> public static void main(String[] args) throws Exception {
>
> Configuration config = Configuration.getConfiguration("default");
>
> try (EventStream es = new RecordingStream(config)) {
>
> es.onEvent("jdk.CPULoad", System.out::println);
> es.startAsync();
> }
>
> TimeUnit.HOURS.sleep(1);
> }
> }
>
> [2]
>
> JFR Event streaming is running asynchronously, but it has been closed. It
> will be terminated immediately.
>
> Regards,
> Chihiro
More information about the hotspot-jfr-dev
mailing list