Can concurrent collection be run in Young Generation for minor collection
Or in other words, is there any algorithm like 'concurrent copy algorithm' which can开发者_运维技巧 help in low pause for minor collections?
Yes, different such algorithms exist.
The easiest to implement Eden / Young-Generation algorithm that can be run concurrently is to just use multiple Edens and also Gen 1 heaps. Depending on which thread is ready (currently not "copy-collecting" which is the "copy everything that is referenced then switch the pointer to the new memory"), that thread will respond with a pointer to the object; threads can identify to which Eden or Gen 1 heap an object belongs by comparing pointers to the min/max-addresses of those heaps.
You can also implement a concurrent copy of a single heap: make a thread-pool and whenever the copy-collection has to take place assign part of the address-range to each thread.
If you need a more specific idea, just specialize your question.
The java.util.concurrent package has many classes to help with this topic area.
For example, CopyOnWriteArrayList, which according to the javadoc is:
A thread-safe variant of ArrayList in which all mutative operations (add, set, and so on) are implemented by making a fresh copy of the underlying array.
If you're concerned about thread-safety (it seems you are), there's probably a class in this package that would be useful to you.
精彩评论