简体   繁体   中英

How to measure latency which appears when threads are awaiting for db connection?

Say I have java application with 10 deamon threads.

Say I have connection pool (for example c3p0) with maximum 3 connections.

Each of threads is working with database. It could happen (ofcourse it really happens) when one thread is waiting for a connection in BLOCKED state.

And I need to measure total thread latency, when each of them is in BLOCKED state awaiting for the connection.

What is the best way to do that?

Extend Thread with your own implementation and Override the method "notify" so it is saving "system.currentTimeMilis" in some kind of cache- you can call a method with the miliseconds argument to take care of the notifyTimes for each thread. Then in your extended thread overide the run/start method and get again the currentTimeMilis. Get the currentTime of the wait method too (again override and dont forget to call the super method in the overridings). Play with these 3 types of times of your threads and you should be able to do your benchmarks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM