multithreading - Java sharing an object between threads -
i have database object stores objects in various data structures. several threads access database, database not date. if change name of object in 1 thread, change reflected in other threads if have not accessed object already. if add new item in 1 thread, threads able view item.
i've tried declaring database object volatile, problem remains , i'm out of ideas...
thanks!
edit: issue traced down not calling .reset() on objectoutputstream
you need synchronize access database object instance.
in java there 2 two basic synchronization idioms:
- synchronized methods (apply
synchronizedkeyword methods accessing database object instance) - synchronized statements (wrap code accessing database object instance inside
synchronizedblock).
Comments
Post a Comment