Mercurial > hg > release > thermostat-1.0
changeset 417:ad3de6c0a03b
Fix timeseries concurrency problem
review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-June/001985.html
reviewed-by: rkennke
author | Mario Torre <neugens.limasoftware@gmail.com> |
---|---|
date | Thu, 21 Jun 2012 23:01:04 +0200 |
parents | 6cef11203d8f |
children | edda32dd535e |
files | client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/HeapDumpController.java client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/chart/OverviewChart.java |
diffstat | 2 files changed, 32 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/HeapDumpController.java Thu Jun 21 12:27:44 2012 -0400 +++ b/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/HeapDumpController.java Thu Jun 21 23:01:04 2012 +0200 @@ -103,6 +103,7 @@ timer.setInitialDelay(0); timer.setDelay(1000); + model.setRange(3600); timer.setTimeUnit(TimeUnit.MILLISECONDS); timer.setSchedulingType(SchedulingType.FIXED_RATE);
--- a/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/chart/OverviewChart.java Thu Jun 21 12:27:44 2012 -0400 +++ b/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/chart/OverviewChart.java Thu Jun 21 23:01:04 2012 +0200 @@ -60,7 +60,8 @@ private static final ColorUIResource MAIN_BAR_BASE_COLOR = new ColorUIResource(0x4A90D9); - + private static final String lock = new String("chartLock"); + private TimeSeries total; private TimeSeries used; private String title; @@ -75,17 +76,25 @@ total = new TimeSeries("total"); total.setDescription("total"); + used = new TimeSeries("used"); used.setDescription("used"); } @Override protected JFreeChart createChart(int width, int height, Color bgColor) { - + TimeSeriesCollection dataset = new TimeSeriesCollection(); - dataset.addSeries(total); - dataset.addSeries(used); - + + synchronized (lock) { + try { + dataset.addSeries(total.createCopy(0, total.getItemCount() - 1)); + dataset.addSeries(used.createCopy(0, used.getItemCount() - 1)); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + } + JFreeChart chart = ChartFactory.createTimeSeriesChart( title, xAxis, @@ -137,14 +146,24 @@ } public void addData(long timeStamp, long used, long total) { + Millisecond millisecond = new Millisecond(new Date(timeStamp)); - if (this.total.getValue(millisecond) == null) { - this.total.add(millisecond, total); - this.total.removeAgedItems(true); + synchronized (lock) { + if (this.total.getValue(millisecond) == null) { + this.total.add(millisecond, total); + this.total.removeAgedItems(true); + } + + if (this.used.getValue(millisecond) == null) { + this.used.add(millisecond, used); + this.used.removeAgedItems(true); + } } - if (this.used.getValue(millisecond) == null) { - this.used.add(millisecond, used); - this.used.removeAgedItems(true); - } + + } + + public void setRange(int seconds) { + total.setMaximumItemCount(seconds); + used.setMaximumItemCount(seconds); } }