Revision: 51681
Updated Code
at October 1, 2011 22:09 by Cur3n4
Updated Code
public class IncDecTimerAdapter implements IncDec { private static Logger logger = ...; private final IncDec incDecToTime; public IncDecTimerAdapter(IncDec incDecToTime) { this.incDecToTime = incDecToTime; } public void increment() { long start = System.currentTimeMillis(); try { incDecToTime.increment(); } finally { long duration = System.currentTimeMillis() - start; logger.debug("Time to increment: %0 (in millis)", duration); } } public void decrement() { long start = System.currentTimeMillis(); try { incDecToTime.decrement(); } finally { long duration = System.currentTimeMillis() - start; logger.debug("Time to decrement: %0 (in millis)", duration); } } }
Revision: 51680
Updated Code
at October 1, 2011 11:02 by Cur3n4
Updated Code
public class IncDecTimerAdapter implements IncDec { private static Logger logger = ...; private final IncDec incDecToTime; public IncDecTimerAdapter(IncDec incDecToTime) { this.incDecToTime = incDecToTime; } public void increment() { long start = System.currentTimeMillis(); try { incDecToTime.increment(); } finally { long duration = System.currentTimeMillis() - start; logger.debug("Time to increment: %1 (in millis)", duration); } } public void decrement() { long start = System.currentTimeMillis(); try { incDecToTime.decrement(); } finally { long duration = System.currentTimeMillis() - start; logger.debug("Time to decrement: %1 (in millis)", duration); } } }
Revision: 51679
Updated Code
at October 1, 2011 10:54 by Cur3n4
Updated Code
public class IncDecTimerAdapter implements IncDec { private final IncDec incDecToTime; public IncDecTimerAdapter(IncDec incDecToTime) { this.incDecToTime = incDecToTime; } public void increment() { long start = System.currentTimeMillis(); try { incDecToTime.increment(); } finally { long duration = System.currentTimeMillis() - start; logger.debug("Time to increment: %1 (in millis)", duration); } } public void decrement() { long start = System.currentTimeMillis(); try { incDecToTime.decrement(); } finally { long duration = System.currentTimeMillis() - start; logger.debug("Time to decrement: %1 (in millis)", duration); } } }
Revision: 51678
Updated Code
at October 1, 2011 10:54 by Cur3n4
Updated Code
public class IncDecTimerAdapter implements IncDec { private final IncDec incDecToTime; public IncDecTimerAdapter(IncDec incDecToTime) { this.incDecToTime = incDecToTime; } public void increment() { long start = System.currentTimeMillis(); try { incDecToTime.increment(); } finally { long duration = System.currentTimeMillis() - start; logger.debug("Time to increment: %1 (in millis)", duration); } } public void decrement() { long start = System.currentTimeMillis(); try { incDecToTime.decrement(); } finally { long duration = System.currentTimeMillis() - start; logger.debug("Time to increment: %1 (in millis)", duration); } } }
Revision: 51677
Updated Code
at October 1, 2011 10:53 by Cur3n4
Updated Code
public class IncDecTimerAdapter implements IncDec { private final IncDec incDecToTime; public IncDecTimerAdapter(IncDec incDecToTime) { this.incDecToTime = incDecToTime; } public void increment() { long start = System.currentTimeMillis(); try { incDecToTime.increment(); } finally { long duration = System.currentTimeMillis() - start; logger.debug("Time to increment: %1 (in millis)", duration); } } public void decrement() { incDecToTime.decrement(); } }
Revision: 51676
Updated Code
at October 1, 2011 10:45 by Cur3n4
Updated Code
public class IncDecTimerAdapter implements IncDec { private final IncDec incDecToTime; public IncDecTimerAdapter(IncDec incDecToTime) { this.incDecToTime = incDecToTime; } }
Revision: 51675
Updated Code
at October 1, 2011 10:44 by Cur3n4
Updated Code
public class IncDecTimerAdapter implements IncDec { public IncDecTimerAdapter(IncDec incDecToTime) { } }
Revision: 51674
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at October 1, 2011 10:41 by Cur3n4
Initial Code
public class IncDecTimerAdapter {}
Initial URL
Initial Description
The idea is to create a proxy class that will delegate the increment and decrement call to MyIncDec implementation while measuring the time. To make it as transparent as possible, the proxy extends the IncDec interface. Beacuse a dependency to the actual IncDec implementation is required, the proxy constructor requires this implementation to be passed in as a parameter. Furthermore, the code of the increment and decrement methods will still measure the duration even if an exception is thrown. Because time measuring (performance analysis) is a cross cutting concern in a real system I would use AOP to define the timing logic just once and apply it to any method as required.
Initial Title
Answer question 1
Initial Tags
Initial Language
Java