multithreading - Should implementations of java.util.Comparator.compare(T o1, T o2) be thread safe? -


or should care when used in parallel implementations java.util.arrays.parallelsort(t[] a, comparator<? super t> cmp) ?

the comparison method nature pure function evaluated against objects may considered immutable @ least during sorting operation. mutating objects during sorting break essential assumption of sorting algorithm, order imposed comparator stable throughout operation.

the above implies that, although comparator must thread-safe when used in parallel sort, given no special effort. on flip side, need make sure doesn't contain thread-unsafe code 1 reason or another, such using thread-unsafe collaborator instance shared across invocations of compare().


Comments

Popular posts from this blog

php - Hide output during test execution -

javascript - Migrate custom AngularJS filter from 1.2.28 to 1.4.x -

Update Magento products with multiple images -