1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > java如何确保单线程_java – 任何单线程程序如何成为有效的多线程程序?

java如何确保单线程_java – 任何单线程程序如何成为有效的多线程程序?

时间:2024-02-09 08:36:40

相关推荐

java如何确保单线程_java – 任何单线程程序如何成为有效的多线程程序?

注意,该语句并不意味着任何正确的单线程程序也是正确的多线程程序,作者只是说明有可能将任何单线程程序转换为在多线程环境中执行.

但是,如果程序在单线程环境中已经不正确,那么在更复杂的多线程环境中它可能不正确.

从书中:

Since any single threaded program is also a valid multithreaded

program, it cannot be thread safe if it is not even correct in a

single threaded environment.

If an object is correctly implemented, no sequence of operations-calls

to public methods and reads or writes of public fields should be able

to violate any of its invariants or post conditions. No set of

operations performed sequentially or concurrently on instances of a

thread safe class can cause an instance to be in an invalid state.

还有这个:

If the loose use of “correctness” here bothers you, you may prefer to

think of a thread safe class as one that is no more broken in a

concurrent environment than in a single threaded environment.

@yshavit在开始考虑多线程正确性之前,请确保至少具有单线程正确性.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。