...chronized),同步化的设定不只可用于方法上,也可以用于某个程式区块上,称之为实例区块同步化(instance block synchronized),例如:
基于12个网页-相关网页
Thread 1 exits the synchronized block and returns instance from the getInstance() method.
线程 1 退出 synchronized 块并从 getInstance() 方法返回实例。
Also, each Home instance is cached once found, so that subsequent lookups will obtain it from the cache, and this cache access is protected with a synchronized block.
而且,一旦找到缓存的主机实例,随后的查找都可以从缓存中获取,这种缓存访问受到同步块的保护。
Then, one thread enters the synchronized block to initialize instance, while the other is blocked.
然后,一个线程进入synchronized块来初始化instance,而另一个线程则被阻断。
应用推荐