开发者

How do I check on whether my synchronized methods are blocking (Android + Java)

开发者 https://www.devze.com 2023-01-29 11:22 出处:网络
I have a feeling that my synchorization may be a little coarse (juddering UI) and was wondering how do I find out when/if m开发者_如何学JAVAy synchronized java methods are blocking on each other.My cu

I have a feeling that my synchorization may be a little coarse (juddering UI) and was wondering how do I find out when/if m开发者_如何学JAVAy synchronized java methods are blocking on each other. My current project is on Android but I am interested in the more general Java case as well.

Thanks,


How does your UI behave if you remove all uses of synchronized from your UI thread? If it's suddenly smooth and responsive, then you know it is indeed blocking for too long while waiting for other threads to release locks.

If however it makes no difference and it's still juddery, you know the problem is your background threads are too busy, i.e. are starving your UI thread of CPU time.


By profiling your application using traceview you can see how much time is spent in each function (Including and excluding the function itself).

I think this should help.

0

精彩评论

暂无评论...
验证码 换一张
取 消