I am trying to create a Container that is initially populated by multiple threads Is this possible with the existing IndexedContainer? I have looked into subclassing IndexedContainer and it seems possible to do this by overriding the addItem and addItemAt methods as synchronized and then passing this container to each thread. Once each populating thread terminates the container is used normally. Does this seem like the correct approach or does Vaadin already have a mechanism to deal with multithreaded container that I have not found?
An example use case is having two tables with different but related data sources and having the need to display the aggregate results and each separately. Originally I had hoped to create two containers and merge the two for the aggregated view, but there does not seem to be a way to merge container items so instead, I create the aggregate and then filter to get the individual parts.
Also, I am using lombok which is as someone else has said, is like programming crack
Sounds good to me. I haven’t done multithreaded containers, but synchronizing the add-methods should do the trick. Or even just synchronizing internalAdd if you don’t need the container to generate id’s. As far as I know, there is no built-in support for containers in a multithreaded environment.
I’m not sure, but if you want you could probably create an aggregating container, but you’d have to deal with conflicting id’s, merging properties with the same id etc. The synchronization method above might actually be simpler to implement.
If you only use the container in a component after it has been fully populated, this sounds ok. If you want to add to it in the background when it has already been attached to a component, you need to synchronize all access to the application instance.
It is not too hard to create your own container based e.g. on AbstractInMemoryContainer, but subclassing IndexedContainer might be the easiest way if working with small datasets and not running into any other limitation of IndexedContainer.