Skip to content

Commit 3407706

Browse files
authored
Fixed synchronization inconsistencies (#4320)
1 parent 0859644 commit 3407706

File tree

8 files changed

+50
-48
lines changed

8 files changed

+50
-48
lines changed

CodenameOne/src/com/codename1/charts/models/XYSeries.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void setTitle(String title) {
148148
* @param x the value for the X axis
149149
* @param y the value for the Y axis
150150
*/
151-
public synchronized void add(double x, double y) {
151+
public void add(double x, double y) {
152152
while (mXY.get(x) != null) {
153153
// add a very small value to x such as data points sharing the same x will
154154
// still be added
@@ -165,7 +165,7 @@ public synchronized void add(double x, double y) {
165165
* @param x the value for the X axis
166166
* @param y the value for the Y axis
167167
*/
168-
public synchronized void add(int index, double x, double y) {
168+
public void add(int index, double x, double y) {
169169
while (mXY.get(x) != null) {
170170
// add a very small value to x such as data points sharing the same x will
171171
// still be added
@@ -184,7 +184,7 @@ protected double getPadding(double x) {
184184
*
185185
* @param index the index in the series of the value to remove
186186
*/
187-
public synchronized void remove(int index) {
187+
public void remove(int index) {
188188
XYEntry<Double, Double> removedEntry = mXY.removeByIndex(index);
189189
double removedX = removedEntry.getKey();
190190
double removedY = removedEntry.getValue();
@@ -196,33 +196,33 @@ public synchronized void remove(int index) {
196196
/**
197197
* Removes all the existing values and annotations from the series.
198198
*/
199-
public synchronized void clear() {
199+
public void clear() {
200200
clearAnnotations();
201201
clearSeriesValues();
202202
}
203203

204204
/**
205205
* Removes all the existing values from the series but annotations.
206206
*/
207-
public synchronized void clearSeriesValues() {
207+
public void clearSeriesValues() {
208208
mXY.clear();
209209
initRange();
210210
}
211211

212212
/**
213213
* Removes all the existing annotations from the series.
214214
*/
215-
public synchronized void clearAnnotations() {
216-
mStringXY.clear();
217-
mAnnotations.clear();
218-
}
215+
public void clearAnnotations() {
216+
mStringXY.clear();
217+
mAnnotations.clear();
218+
}
219219

220220
/**
221221
* Returns the current values that are used for drawing the series.
222222
*
223223
* @return the XY map
224224
*/
225-
public synchronized IndexXYMap<Double, Double> getXYMap() {
225+
public IndexXYMap<Double, Double> getXYMap() {
226226
return mXY;
227227
}
228228

@@ -232,7 +232,7 @@ public synchronized IndexXYMap<Double, Double> getXYMap() {
232232
* @param index the index
233233
* @return the X value
234234
*/
235-
public synchronized double getX(int index) {
235+
public double getX(int index) {
236236
return mXY.getXByIndex(index);
237237
}
238238

@@ -242,7 +242,7 @@ public synchronized double getX(int index) {
242242
* @param index the index
243243
* @return the Y value
244244
*/
245-
public synchronized double getY(int index) {
245+
public double getY(int index) {
246246
return mXY.getYByIndex(index);
247247
}
248248

@@ -335,7 +335,7 @@ public String getAnnotationAt(int index) {
335335
* visible ones must be displayed
336336
* @return a submap of x and y values
337337
*/
338-
public synchronized SortedMap<Double, Double> getRange(double start, double stop,
338+
public SortedMap<Double, Double> getRange(double start, double stop,
339339
boolean beforeAfterPoints) {
340340
if (beforeAfterPoints) {
341341
// we need to add one point before the start and one point after the end
@@ -379,7 +379,7 @@ public int getIndexForKey(double key) {
379379
*
380380
* @return the series item count
381381
*/
382-
public synchronized int getItemCount() {
382+
public int getItemCount() {
383383
return mXY.size();
384384
}
385385

CodenameOne/src/com/codename1/charts/models/XYValueSeries.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public XYValueSeries(String title) {
4848
* @param y the value for the Y axis
4949
* @param value the value
5050
*/
51-
public synchronized void add(double x, double y, double value) {
51+
public void add(double x, double y, double value) {
5252
super.add(x, y);
5353
mValue.add(value);
5454
updateRange(value);
@@ -82,7 +82,7 @@ private void updateRange(double value) {
8282
* @param x the value for the X axis
8383
* @param y the value for the Y axis
8484
*/
85-
public synchronized void add(double x, double y) {
85+
public void add(double x, double y) {
8686
add(x, y, 0d);
8787
}
8888

@@ -91,7 +91,7 @@ public synchronized void add(double x, double y) {
9191
*
9292
* @param index the index in the series of the value to remove
9393
*/
94-
public synchronized void remove(int index) {
94+
public void remove(int index) {
9595
super.remove(index);
9696
double removedValue = mValue.remove(index);
9797
if (removedValue == mMinValue || removedValue == mMaxValue) {
@@ -102,7 +102,7 @@ public synchronized void remove(int index) {
102102
/**
103103
* Removes all the values from the series.
104104
*/
105-
public synchronized void clear() {
105+
public void clear() {
106106
super.clear();
107107
mValue.clear();
108108
initRange();
@@ -114,7 +114,7 @@ public synchronized void clear() {
114114
* @param index the index
115115
* @return the value
116116
*/
117-
public synchronized double getValue(int index) {
117+
public double getValue(int index) {
118118
return mValue.get(index);
119119
}
120120

CodenameOne/src/com/codename1/io/BufferedInputStream.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*/
3535
public class BufferedInputStream extends InputStream {
3636
private static int streamCount = 0;
37-
private static int defaultBufferSize = 8192;
37+
private static volatile int defaultBufferSize = 8192;
3838
private int actualAvailable = defaultBufferSize;
3939
private Object connection;
4040
private InputStream in;
@@ -212,10 +212,10 @@ public String getName() {
212212
}
213213

214214
/**
215-
* Check to make sure that underlying input stream has not been
215+
* Check to make sure that the underlying input stream has not been
216216
* nulled out due to close; if not return it;
217217
*/
218-
private InputStream getInIfOpen() throws IOException {
218+
private synchronized InputStream getInIfOpen() throws IOException {
219219
InputStream input = in;
220220
if (input == null) {
221221
throw new IOException("Stream closed");
@@ -227,7 +227,7 @@ private InputStream getInIfOpen() throws IOException {
227227
* Check to make sure that buffer has not been nulled out due to
228228
* close; if not return it;
229229
*/
230-
private byte[] getBufIfOpen() throws IOException {
230+
private synchronized byte[] getBufIfOpen() throws IOException {
231231
byte[] buffer = buf;
232232
if (buffer == null) {
233233
throw new IOException("Stream closed");
@@ -377,7 +377,7 @@ private int read1(byte[] b, int off, int len) throws IOException {
377377
return cnt;
378378
}
379379

380-
private void yieldTime() {
380+
private synchronized void yieldTime() {
381381
long time = System.currentTimeMillis();
382382
if (time - elapsedSinceLastYield > 300) {
383383
try {
@@ -656,16 +656,16 @@ public void close() throws IOException {
656656
*
657657
* @return time of the last activity on this stream
658658
*/
659-
public long getLastActivityTime() {
659+
public synchronized long getLastActivityTime() {
660660
return lastActivityTime;
661661
}
662662

663663
/**
664-
* Returns the total amount of bytes read from this stream so far
664+
* Returns the total number of bytes read from this stream so far
665665
*
666-
* @return the total amount of bytes read from this stream so far
666+
* @return the total number of bytes read from this stream so far
667667
*/
668-
public int getTotalBytesRead() {
668+
public synchronized int getTotalBytesRead() {
669669
return totalBytesRead;
670670
}
671671

@@ -706,14 +706,14 @@ public void setConnection(Object connection) {
706706
/**
707707
* @return the disableBuffering
708708
*/
709-
public boolean isDisableBuffering() {
709+
public synchronized boolean isDisableBuffering() {
710710
return disableBuffering;
711711
}
712712

713713
/**
714714
* @param disableBuffering the disableBuffering to set
715715
*/
716-
public void setDisableBuffering(boolean disableBuffering) {
716+
public synchronized void setDisableBuffering(boolean disableBuffering) {
717717
this.disableBuffering = disableBuffering;
718718
}
719719

@@ -723,7 +723,7 @@ public void setDisableBuffering(boolean disableBuffering) {
723723
*
724724
* @return the printInput
725725
*/
726-
public boolean isPrintInput() {
726+
public synchronized boolean isPrintInput() {
727727
return printInput;
728728
}
729729

@@ -733,7 +733,7 @@ public boolean isPrintInput() {
733733
*
734734
* @param printInput the printInput to set
735735
*/
736-
public void setPrintInput(boolean printInput) {
736+
public synchronized void setPrintInput(boolean printInput) {
737737
this.printInput = printInput;
738738
}
739739

@@ -743,7 +743,7 @@ public void setPrintInput(boolean printInput) {
743743
*
744744
* @return the yield
745745
*/
746-
public int getYield() {
746+
public synchronized int getYield() {
747747
return yield;
748748
}
749749

@@ -753,15 +753,15 @@ public int getYield() {
753753
*
754754
* @param yield the yield to set
755755
*/
756-
public void setYield(int yield) {
756+
public synchronized void setYield(int yield) {
757757
this.yield = yield;
758758
}
759759

760760
/**
761761
* Stop reading from the stream, invoking this will cause the read() to
762762
* return -1
763763
*/
764-
public void stop() {
764+
public synchronized void stop() {
765765
stopped = true;
766766
}
767767

CodenameOne/src/com/codename1/io/BufferedOutputStream.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public String getName() {
137137
/**
138138
* Flush the internal buffer
139139
*/
140-
public void flushBuffer() throws IOException {
140+
public synchronized void flushBuffer() throws IOException {
141141
if (closed) {
142142
return;
143143
}
@@ -218,7 +218,7 @@ public synchronized void flush() throws IOException {
218218
*
219219
* @return time of the last activity on this stream
220220
*/
221-
public long getLastActivityTime() {
221+
public synchronized long getLastActivityTime() {
222222
return lastActivityTime;
223223
}
224224

@@ -227,7 +227,7 @@ public long getLastActivityTime() {
227227
*
228228
* @return the total amount of bytes written to this stream so far
229229
*/
230-
public int getTotalBytesWritten() {
230+
public synchronized int getTotalBytesWritten() {
231231
return totalBytesWritten;
232232
}
233233

CodenameOne/src/com/codename1/l10n/DateFormatSymbols.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,14 @@ public void setAmPmStrings(String[] newAmpms) {
9090
ampms = newAmpms;
9191
}
9292

93-
public Hashtable<String, String> getResourceBundle() {
93+
public synchronized Hashtable<String, String> getResourceBundle() {
9494
return resourceBundle;
9595
}
9696

9797
public void setResourceBundle(Hashtable<String, String> newResourceBundle) {
98-
this.resourceBundle = newResourceBundle;
98+
synchronized (this) {
99+
this.resourceBundle = newResourceBundle;
100+
}
99101
// force rebuild
100102
ampms = null;
101103
months = null;

CodenameOne/src/com/codename1/ui/Display.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2919,7 +2919,7 @@ public void setVirtualKeyboardListener(ActionListener l) {
29192919
* @see #removeVirtualKeyboardListener(com.codename1.ui.events.ActionListener)
29202920
* @since 6.0
29212921
*/
2922-
public synchronized void addVirtualKeyboardListener(ActionListener l) {
2922+
public void addVirtualKeyboardListener(ActionListener l) {
29232923
if (virtualKeyboardListeners == null) {
29242924
virtualKeyboardListeners = new EventDispatcher();
29252925
}
@@ -2937,7 +2937,7 @@ public synchronized void addVirtualKeyboardListener(ActionListener l) {
29372937
* @see #addVirtualKeyboardListener(com.codename1.ui.events.ActionListener)
29382938
* @since 6.0
29392939
*/
2940-
public synchronized void removeVirtualKeyboardListener(ActionListener l) {
2940+
public void removeVirtualKeyboardListener(ActionListener l) {
29412941
if (virtualKeyboardListeners != null) {
29422942
virtualKeyboardListeners.removeListener(l);
29432943
}
@@ -3422,7 +3422,7 @@ public void dispatchMessage(MessageEvent evt) {
34223422
*
34233423
* @param l the listener to add
34243424
*/
3425-
public synchronized void addWindowListener(ActionListener<WindowEvent> l) {
3425+
public void addWindowListener(ActionListener<WindowEvent> l) {
34263426
if (windowListeners == null) {
34273427
windowListeners = new EventDispatcher();
34283428
}
@@ -3434,7 +3434,7 @@ public synchronized void addWindowListener(ActionListener<WindowEvent> l) {
34343434
*
34353435
* @param l the listener to remove
34363436
*/
3437-
public synchronized void removeWindowListener(ActionListener<WindowEvent> l) {
3437+
public void removeWindowListener(ActionListener<WindowEvent> l) {
34383438
if (windowListeners != null) {
34393439
windowListeners.removeListener(l);
34403440
}
@@ -5222,7 +5222,7 @@ private class EdtException extends RuntimeException {
52225222
private Throwable cause;
52235223
private EdtException parent;
52245224

5225-
public synchronized Throwable getCause() {
5225+
public Throwable getCause() {
52265226
return cause;
52275227
}
52285228

CodenameOne/src/com/codename1/ui/Image.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,15 +1576,15 @@ public boolean requiresDrawImage() {
15761576
}
15771577

15781578
@Override
1579-
public synchronized void addActionListener(ActionListener l) {
1579+
public void addActionListener(ActionListener l) {
15801580
if (listeners == null) {
15811581
listeners = new EventDispatcher();
15821582
}
15831583
listeners.addListener(l);
15841584
}
15851585

15861586
@Override
1587-
public synchronized void removeActionListener(ActionListener l) {
1587+
public void removeActionListener(ActionListener l) {
15881588
if (listeners != null) {
15891589
listeners.removeListener(l);
15901590
}

CodenameOne/src/com/codename1/ui/html/ResourceThreadQueue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ synchronized int getCSSCount() {
186186
*
187187
* @return the queue size
188188
*/
189-
int getQueueSize() {
189+
synchronized int getQueueSize() {
190190
return (images.size() + queue.size()); // CSS files are added directly to queue while images to the images vector
191191
//return queue.size();
192192
}

0 commit comments

Comments
 (0)