It make JFR Event Streaming asynchronously with try-catch-resources more understandable

Chihiro Ito chiroito107 at gmail.com
Sun Feb 16 15:21:07 UTC 2020


Hi Erik,

Thanks for the quick response.

My offer is just output a log. I think we need not change the current
implementation.
When users to use JFR Event Streaming with try-catch-resources, It is too
difficult for the user to understand why JFR Event Streaming is stopped
after running try-catch-resources.
For this reason,  if the user runs JFR Event Streaming asynchronously and
when being called close() method as AutoClosable,  JFR Event Streaming will
be stopped.
When I had tried to use JFR Event Streaming with try-catch-resources, I
hard to find this cause why it is stopped.
If we implement to output that for example "JFR Event Streaming on async
will be stopped" like a log message, the user easy to find the cause of
stopping.

Regards,
Chihiro

2020年2月16日(日) 23:29 Erik Gahlin <erik.gahlin at oracle.com>:

> 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