How it works...

When you execute the example, you will see how the execution time of the TaskAtomic tasks that use atomic variables are always better than the TaskLock tasks that use locks. You will obtain a similar result if you use the synchronized keyword instead of locks.

The conclusion of this recipe is that utilization of atomic variables will give you better performance than other synchronization methods. If you don't have an atomic type that fits your needs, maybe you can try to implement your own atomic type.

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

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