wilkas wilkas - 1 year ago 36
Java Question

Writing to same ArrayList from several methods at the same time

I have several data listeners, which may receive datasets roughly at the same time. They will iterate datasets and store data to the same

by using its method
. Could this potentially cause any issues of some data items not being stored?

Answer Source

You can use synchronized block in this case :

synchronized (this){
    // ...

You can find a good examples here Synchronized

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download