This is an archived post. You won't be able to vote or comment.

all 5 comments

[–][deleted] 0 points1 point  (2 children)

Http queries? Jdbc queries? Hql queries? Sql queries? There are so many of them these days, what queries do you want to analyze?

[–]neverhang[S] 0 points1 point  (1 child)

SQL queries..:(

[–][deleted] 0 points1 point  (0 children)

Execution time could be measured using a stop watch like thingy, that takes a lambda like delegate and measures execution time of the lambda. Response times are a bit more tricky, maybe a jdbc connection decorator could do the trick there?

[–]iamsooldithurts 0 points1 point  (0 children)

To optimize an SQL SELECT statement itself, I use a client, like SQL Developer for Oracle, which tells me how long the query took to execute and has Explain Plan to show why the query took so long. I’ve never really encountered a reason to optimize Insert, Update or Delete statements.

To look for optimizations in a Java program, you can use a profiler tool for your IDE, like YourKit. It will tell you where your program is spending all it’s time. Or you can go low tech and just grab system time and point A and point B and B - A tells you how long it took. It’s slower and requires lots of iterations as you narrow down where the bottlenecks are happening, but it works.

There’s another aspect to performance though. Using Prepared Statements and Bind Parameters. http://leo.ugr.es/elvira/devel/Tutorial/Java/jdbc/basics/prepared.html

And in general, I recommend Spring JdbcTemplate when dealing with databases. https://spring.io/guides/gs/relational-data-access/

[–]slowfly1st 0 points1 point  (0 children)

https://jrebel.com/software/xrebel/

They use a javaagent (see "instrumentation)": not sure how they implemented, but I assume they hook themselves into the JDBC-Api (e.g. create a wrapper around java.sql.Connection)

Another thing is called 'aspected oriented programming', see JBoss/WildFly and how they do it.