@@ -51,15 +51,13 @@ open class Model(
5151 * specified, must also specify [_parentModel]
5252 */
5353 private val _parentProperty : String? = null ,
54- private val modelSynchronizationLock : Any = Any (),
54+ private val initializationLock : Any = Any (),
5555) : IEventNotifier<IModelChangedHandler> {
5656 /* *
5757 * A unique identifier for this model.
5858 */
5959 var id: String
60- get() = synchronized(modelSynchronizationLock) {
61- getStringProperty(::id.name)
62- }
60+ get() = getStringProperty(::id.name)
6361 set(value) {
6462 setStringProperty(::id.name, value)
6563 }
@@ -126,7 +124,7 @@ open class Model(
126124 id : String? ,
127125 model : Model ,
128126 ) {
129- val newData = mutableMapOf<String , Any ?>()
127+ val newData = Collections .synchronizedMap( mutableMapOf<String , Any ?>() )
130128
131129 for (item in model.data) {
132130 if (item.value is Model ) {
@@ -142,7 +140,7 @@ open class Model(
142140 newData[::id.name] = id
143141 }
144142
145- synchronized(modelSynchronizationLock ) {
143+ synchronized(initializationLock ) {
146144 data.clear()
147145 data.putAll(newData)
148146 }
@@ -669,7 +667,7 @@ open class Model(
669667 * @return The resulting [JSONObject].
670668 */
671669 fun toJSON (): JSONObject {
672- synchronized(modelSynchronizationLock ) {
670+ synchronized(initializationLock ) {
673671 val jsonObject = JSONObject ()
674672 for (kvp in data) {
675673 when (val value = kvp.value) {
@@ -701,7 +699,5 @@ open class Model(
701699 override fun unsubscribe (handler : IModelChangedHandler ) = changeNotifier.unsubscribe(handler)
702700
703701 override val hasSubscribers: Boolean
704- get() = synchronized(modelSynchronizationLock) {
705- changeNotifier.hasSubscribers
706- }
702+ get() = changeNotifier.hasSubscribers
707703}
0 commit comments