Make Split AutoCloseable

13 views
Skip to first unread message

Vitaly Litvak

unread,
Jul 24, 2014, 6:27:21 AM7/24/14
to java...@googlegroups.com
Hi.

Thanks for an awesome library. I would like to make a suggestion.

There are cases when one wants to measure execution time of some method. In such case he may surround method body with try ... finally block:

public int myMethod() {
    Split s = SimonManager.getStopwatch("myMethod").start();
    try {
       
// method body
       
return 5;
    } finally {
        s
.stop();
    }
}

I suggest to implement AutoCloseable (avlbl since 1.7) or simply Closeable (avlbl since 1.5) interface and call stop() method in implementation of close(). This will make such code look better when environment version is >= 1.7:

public int myMethod() {
    try (
Split s = SimonManager.getStopwatch("myMethod").start() {
        // method body
        return 5;
    }
}

This can be easily done. I can create some kind of pull request. What do you think?

Best regards, Vitaly Litvak

Richard Richter

unread,
Jul 24, 2014, 7:19:46 AM7/24/14
to java...@googlegroups.com
Hi Vitaly

I see you created an issue for us:
https://code.google.com/p/javasimon/issues/detail?id=127

Thanks for it, idea is good and cause no problem I think - next
release requires Java 7 anyway.

I'll try to release 4.0 until the end of the holiday, so stay tuned.

Virgo
> --
> You received this message because you are subscribed to the Google Groups
> "javasimon" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to javasimon+...@googlegroups.com.
> To post to this group, send email to java...@googlegroups.com.
> Visit this group at http://groups.google.com/group/javasimon.
> For more options, visit https://groups.google.com/d/optout.

Vitaly Litvak

unread,
Jul 24, 2014, 7:56:58 AM7/24/14
to java...@googlegroups.com
Sounds good. Thank you very much. 

Actually I have created that issue because thread didn't appear on google groups. So please excuse me for spamming.

четверг, 24 июля 2014 г., 15:19:46 UTC+4 пользователь Virgo47 написал:

Richard Richter

unread,
Jul 24, 2014, 7:58:31 AM7/24/14
to java...@googlegroups.com
No problem, we had to start moderating because of the spammers/bots,
but I always welcome when the issue is filed. ;-)
V.
Reply all
Reply to author
Forward
0 new messages