Skip to content

Commit ef665eb

Browse files
tulinkryVladimir Kotal
authored andcommitted
using statistics with synchronized methods (#1563)
1 parent cfb0b5c commit ef665eb

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/org/opensolaris/opengrok/web/Statistics.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class Statistics {
6767
/**
6868
* Adds a single request into all requests.
6969
*/
70-
public void addRequest(HttpServletRequest req) {
70+
synchronized public void addRequest(HttpServletRequest req) {
7171
maybeRefresh();
7272

7373
requestsPerMinute++;
@@ -87,7 +87,7 @@ public void addRequest(HttpServletRequest req) {
8787
/**
8888
* Refreshes the last timestamp and number of minutes since start if needed.
8989
*/
90-
protected void maybeRefresh() {
90+
synchronized protected void maybeRefresh() {
9191
if (timeStart + 60 * 1000 <= System.currentTimeMillis()) {
9292
// several minutes have passed
9393
minutes += (System.currentTimeMillis() - timeStart) / (60 * 1000);
@@ -102,7 +102,7 @@ protected void maybeRefresh() {
102102
* @param req the given request
103103
* @param category category
104104
*/
105-
public void addRequest(HttpServletRequest req, String category) {
105+
synchronized public void addRequest(HttpServletRequest req, String category) {
106106
Long val = requestCategories.get(category);
107107
if (val == null) {
108108
val = new Long(0);
@@ -118,7 +118,7 @@ public void addRequest(HttpServletRequest req, String category) {
118118
* @param category category
119119
* @param v time spent on processing this request
120120
*/
121-
public void addRequestTime(HttpServletRequest req, String category, long v) {
121+
synchronized public void addRequestTime(HttpServletRequest req, String category, long v) {
122122
addRequest(req, category);
123123
Long val = timing.get(category);
124124
Long min = timingMin.get(category);
@@ -172,35 +172,35 @@ public Map<String, Double> getTimingAvg() {
172172
return timingAvg;
173173
}
174174

175-
public void setRequestCategories(Map<String, Long> requestCategories) {
175+
synchronized public void setRequestCategories(Map<String, Long> requestCategories) {
176176
this.requestCategories = requestCategories;
177177
}
178178

179-
public void setTiming(Map<String, Long> timing) {
179+
synchronized public void setTiming(Map<String, Long> timing) {
180180
this.timing = timing;
181181
}
182182

183-
public void setTimingMin(Map<String, Long> timing_min) {
183+
synchronized public void setTimingMin(Map<String, Long> timing_min) {
184184
this.timingMin = timing_min;
185185
}
186186

187-
public void setTimingMax(Map<String, Long> timing_max) {
187+
synchronized public void setTimingMax(Map<String, Long> timing_max) {
188188
this.timingMax = timing_max;
189189
}
190190

191191
public long getTimeStart() {
192192
return timeStart;
193193
}
194194

195-
public void setTimeStart(long timeStart) {
195+
synchronized public void setTimeStart(long timeStart) {
196196
this.timeStart = timeStart;
197197
}
198198

199199
public long getRequests() {
200200
return requests;
201201
}
202202

203-
public void setRequests(long requests) {
203+
synchronized public void setRequests(long requests) {
204204
this.requests = requests;
205205
}
206206

@@ -209,7 +209,7 @@ public long getMinutes() {
209209
return minutes;
210210
}
211211

212-
public void setMinutes(long minutes) {
212+
synchronized public void setMinutes(long minutes) {
213213
this.minutes = minutes;
214214
}
215215

@@ -218,7 +218,7 @@ public long getRequestsPerMinute() {
218218
return requestsPerMinute;
219219
}
220220

221-
public void setRequestsPerMinute(long requestsPerMinute) {
221+
synchronized public void setRequestsPerMinute(long requestsPerMinute) {
222222
this.requestsPerMinute = requestsPerMinute;
223223
}
224224

@@ -229,7 +229,7 @@ public long getRequestsPerMinuteMin() {
229229
return requestsPerMinuteMin;
230230
}
231231

232-
public void setRequestsPerMinuteMin(long requestsPerMinuteMin) {
232+
synchronized public void setRequestsPerMinuteMin(long requestsPerMinuteMin) {
233233
this.requestsPerMinuteMin = requestsPerMinuteMin;
234234
}
235235

@@ -240,7 +240,7 @@ public long getRequestsPerMinuteMax() {
240240
return requestsPerMinuteMax;
241241
}
242242

243-
public void setRequestsPerMinuteMax(long requestsPerMinuteMax) {
243+
synchronized public void setRequestsPerMinuteMax(long requestsPerMinuteMax) {
244244
this.requestsPerMinuteMax = requestsPerMinuteMax;
245245
}
246246

@@ -253,15 +253,15 @@ public long[] getDayHistogram() {
253253
return dayHistogram;
254254
}
255255

256-
public void setDayHistogram(long[] dayHistogram) {
256+
synchronized public void setDayHistogram(long[] dayHistogram) {
257257
this.dayHistogram = dayHistogram;
258258
}
259259

260260
public long[] getMonthHistogram() {
261261
return monthHistogram;
262262
}
263263

264-
public void setMonthHistogram(long[] monthHistogram) {
264+
synchronized public void setMonthHistogram(long[] monthHistogram) {
265265
this.monthHistogram = monthHistogram;
266266
}
267267

0 commit comments

Comments
 (0)