EntityContainer and multi-threading ? (Zay-ES)

Paul is it safe to call update(); on EntityContainer from one thread and getArray() from other thread ?

Looking at source code of EntityContainer<T> class

private Map<EntityId, T> objects = new HashMap<>();

 protected T[] getArray() {
        if( array != null ) {
            return array;
        array = (T[])Array.newInstance(parameter, objects.size());
        array = objects.values().toArray(array);
        return array;

it seems it is not safe to do, can you confirm please ?

EntityContainer is single threaded. Even wanting to use one non-single threaded is a bit strange and brings design into question.

1 Like

Yes, I had a feeling that this seems to be a bad practice. Thanks for making it clear for me. Will find a better solution.

Actually i want to put assetmanager to load model in an other thread then when ready i will add it to scene in ModelViewState. I will think for a good solution. :slight_smile:

Well, usually that’s a send a request to another thread, receive a response from that thread. The entity container isn’t involved in that… as it’s still on the main thread.

1 Like