tag:blogger.com,1999:blog-318596391703166199.post2783546341726825232..comments2023-08-07T23:23:15.074-07:00Comments on Advanced Reactive Java: Subjects (part 3 - final)David Karnokhttp://www.blogger.com/profile/07920580392321059533noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-318596391703166199.post-14552995112487340662015-11-04T14:35:11.141-08:002015-11-04T14:35:11.141-08:00There are several reasons. The most obvious is tha...There are several reasons. The most obvious is that it saves on object headers. Second, the list can be concurrently modified when a Subscriber subscribes and there is an emission looping through it. The emission thread has to see a consistent view of the available subscribers. ArrayList can't give such guarantees and iterating a CHM is expensive. <br /><br />So the best option for small number of active subscribers is to have an "immutable" list and perform copy-on-write whenever a Subscriber subscribes or unsubscribes.<br /><br />For large number of subscribers, I proposed a OpenHashSet + cached array. The idea is that as Subscribers arrive or go in masses, there has to be only one array-copying happen per such group.David Karnokhttps://www.blogger.com/profile/07920580392321059533noreply@blogger.comtag:blogger.com,1999:blog-318596391703166199.post-47897045776942722302015-11-04T14:15:04.154-08:002015-11-04T14:15:04.154-08:00Why use an array for the subscriber list instead o...Why use an array for the subscriber list instead of an ArrayList? It seems like you could skip a lot of array creation/array copies that way.Danielhttps://www.blogger.com/profile/17003436808680466962noreply@blogger.com