As probably some of you know, mainly Aslak and Alex, I was extracting that Arquillian Cube runtime into Arquillian-less solution so I can manage lifecycle of containers manually by firing respective management events.
The thing is that, when you look at it realistically, you can start containers which do not depend on any other container in parallel. Right now I am doing it sequentially hence I could potentially save some startup time.
So the first naive approach was to do it like this:
listOfContainers.parallelStream().forEach(container -> manager.start(container.getName()))
manager is just a wrapper which internally fires
The result of this was that it got it kind of mangled and underlying Core manager ended up with some weird exceptions. I do not have a log at hand right now but I could make some reproducer on demand.
How to make this thread safe? Is core manager thread safe? I guess it is not because it observes events as they are fired and there is not any notion of "threadness" in it so only events logically coupled in one thread would be executed in some kind of isolated state from all other ones.
Is it a bad idea to put Arquillian core manager to some thread pool so I would have multiple of them and I would then submit a task to Executor service which would fire events so eventually every core manager would execute in a separate thread hence it would not clash?