Java 线程分析:确定线程等待特定锁以及每次等待的持续时间
我有一个使用线程的 Java 应用程序,它使用多个 Lock 对象实例来同步对公共资源的访问。
现在,作为性能测量的一部分,我想测量每个线程在每个锁中花费的时间。到目前为止我已经尝试过 NetBeans 探查器。
Netbeans 探查器向我显示线程的总等待时间,但无法知道线程在哪个锁中等待了多长时间。
对于这种测量,您会推荐哪种工具?
干杯
I have a Java application using threads, which uses several Lock object instances to synchronize access to common resources.
Now as part of a performance measurement I want to measure the time spent by each thread in every lock. I have tried so far NetBeans profiler.
Netbeans profiler shows me the total wait time for a thread but it is impossible to know how much time in which lock the thread waited.
Which tool will you recommend for this kind of measurement?
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您需要的具体数据,您可以从 Java 程序中获取此信息。例如,类似这样的操作将在 100 秒内每秒对持有的锁进行 20 次采样,从而有效地创建一个 lock > > 的映射。锁定的大致时间(锁定给定锁的“滴答数”):
根据需要进行调整以收集数据。
然后您可以在后台线程中启动此操作,例如:
Depending on exactly what data you need, you can just get this information from within your Java program. For example, something like this will sample held locks 20 times a second for 100 seconds, creating effectively a map of lock > approximate time locked (number of "ticks" during which the given lock was being locked on):
Adapt to collect the data as you need it.
You can then start this going in a background thread e.g.: