Lazy delegation

You may wonder what happens if two threads try to initialize the image at the same time. By default, the lazy() function is synchronized. Only one thread will win, and others will wait until the image is ready.

If you don't mind two threads executing the lazy block (it's not that expensive, for example), you can use by lazy(LazyThreadSafetyMode.PUBLICATION).

If performance is absolutely critical to you, and you're absolutely sure that two threads won't ever execute the same block simultaneously, you can use LazyThreadSafetyMode.NONE.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.198.81