Skip to content

Commit d40bd8d

Browse files
committed
Revert "Threads for onUpdate and onNotify"
This reverts commit 42b661a.
1 parent 68bd9ca commit d40bd8d

File tree

2 files changed

+15
-27
lines changed

2 files changed

+15
-27
lines changed

src/main/java/org/json/JSONObject.java

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,20 +1854,16 @@ public JSONObject update(String key, Object newValue) throws JSONException {
18541854
final Object oldValue = this.opt(key);
18551855
this.put(key, newValue);
18561856

1857+
this.propertyChangeSupportUpdate.firePropertyChange(JSONObject.propertyChangeGlobalKeyword, oldThis, this);
1858+
this.propertyChangeSupportUpdate.firePropertyChange(key, oldValue, newValue);
18571859

1858-
new Thread(() -> {
1859-
this.propertyChangeSupportUpdate.firePropertyChange(JSONObject.propertyChangeGlobalKeyword, oldThis, this);
1860-
this.propertyChangeSupportUpdate.firePropertyChange(key, oldValue, newValue);
1861-
this.propertyChangeSupportNotify.firePropertyChange(key, oldValue, newValue);
1862-
}, "json" + key).start();
1860+
this.propertyChangeSupportNotify.firePropertyChange(key, oldValue, newValue);
18631861

18641862
return this;
18651863
}
18661864

18671865
public JSONObject notify(String key, Object oldValue, Object newValue) throws JSONException {
1868-
new Thread(() -> {
1869-
this.propertyChangeSupportNotify.firePropertyChange(key, oldValue, newValue);
1870-
}, "json" + key).start();
1866+
this.propertyChangeSupportNotify.firePropertyChange(key, oldValue, newValue);
18711867

18721868
return this;
18731869
}
@@ -1952,21 +1948,19 @@ private JSONObject updateOrRemove(JSONObject jo, boolean remove, boolean trigger
19521948
}
19531949

19541950
if (oldValues.size() > 0) {
1955-
new Thread(() -> {
1956-
if (triggerUpdate) {
1957-
this.propertyChangeSupportUpdate.firePropertyChange(JSONObject.propertyChangeGlobalKeyword, oldThis, this);
1958-
}
1951+
if (triggerUpdate) {
1952+
this.propertyChangeSupportUpdate.firePropertyChange(JSONObject.propertyChangeGlobalKeyword, oldThis, this);
1953+
}
19591954

1960-
oldValues.forEach((key, oldValue) -> {
1961-
final Object v2 = delValues.contains(key) ? null : newValues.get(key);
1962-
final Object v1 = oldValue == null && v2 == null ? JSONObject.NULL : oldValue;
1955+
oldValues.forEach((key, oldValue) -> {
1956+
final Object v2 = delValues.contains(key) ? null : newValues.get(key);
1957+
final Object v1 = oldValue == null && v2 == null ? JSONObject.NULL : oldValue;
19631958

1964-
if (triggerUpdate) {
1965-
this.propertyChangeSupportUpdate.firePropertyChange(key, v1, v2);
1966-
}
1967-
this.propertyChangeSupportNotify.firePropertyChange(key, v1, v2);
1968-
});
1969-
}, "json_GLOBAL").start();
1959+
if (triggerUpdate) {
1960+
this.propertyChangeSupportUpdate.firePropertyChange(key, v1, v2);
1961+
}
1962+
this.propertyChangeSupportNotify.firePropertyChange(key, v1, v2);
1963+
});
19701964
}
19711965

19721966
return this;

src/test/java/org/json/junit/JSONTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,12 +473,6 @@ public void updateListenerGlobalTest() {
473473
j.update("myMapListener", "propertyChange456");
474474
j.update("myMapListener", "propertyChange789");
475475

476-
try {
477-
Thread.sleep(1L);
478-
} catch (InterruptedException ex) {
479-
ex.printStackTrace();
480-
}
481-
482476
assertEquals(counter.get(), globalExecutions.get() * 3);
483477
}
484478

0 commit comments

Comments
 (0)