Brian Goetz's improper publication

前端 未结 2 1488
春和景丽
春和景丽 2020-12-11 10:34

The question has been posted before but no real example was provided that works. So Brian mentions that under certain conditions the AssertionError can occur in the followin

2条回答
  •  孤城傲影
    2020-12-11 11:22

    Your program is not properly synchronized, as that term is defined by the Java Memory Model.

    That does not, however, mean that any particular run will exhibit the assertion failure you are looking for, nor that you necessarily can expect ever to see that failure. It may be that your particular VM just happens to handle that particular program in a way that turns out never to expose that synchronization failure. Or it may turn out the although susceptible to failure, the likelihood is remote.

    And no, your test does not provide any justification for writing code that fails to be properly synchronized in this particular way. You cannot generalize from these observations.

提交回复
热议问题