Is there a tool to determine whether a program is “correctly synchronized” as defined in JLS?

流过昼夜 提交于 2020-01-04 04:19:32

问题


The Java Language Specification 7 (JLS7-17.4.5) defines a "correctly synchronized" program like this: "A program is correctly synchronized if and only if all sequentially consistent executions are free of data races".

JLS7-17.4.5 also states that:

Without correct synchronization, very strange, confusing and counterintuitive behaviors are possible.

So, from a programmer's point of view, it would be very useful to have a tool to determine whether a program is "correctly synchronized" according the the above definition.

Is there such a tool? I could not find anything by Googling on it. If there is no such tool, would it be possible to make one?


回答1:


FindBugs can find some concurrency bugs (search for "Multithreaded correctness" on the list of detected bugs) and there probably are other similar tools, but in the end some bugs can only be avoided with meticulous code design and review.

You can also test your classes for concurrency issues, but it is a game of statistics and some bugs might never show up depending on OS/CPU architecture etc.

I have heard about the Java concurrency torture tool, but never used it. It has been mentioned several times on the official JSR 166 Concurrency Interest list.



来源:https://stackoverflow.com/questions/14400044/is-there-a-tool-to-determine-whether-a-program-is-correctly-synchronized-as-de

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!