jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1205992 - in /jmeter/trunk/src/components/org/apache/jmeter/timers: BarrierWrapper.java SyncTimer.java SyncTimer.java.tmp SyncTimer.java.tmp2
Date Thu, 24 Nov 2011 22:00:56 GMT
Author: pmouawad
Date: Thu Nov 24 22:00:55 2011
New Revision: 1205992

URL: http://svn.apache.org/viewvc?rev=1205992&view=rev
Log:
Bug 52183 - SyncTimer could be improved (performance+reliability)
Made BarrierWrapper class private and commented setup.

Removed:
    jmeter/trunk/src/components/org/apache/jmeter/timers/BarrierWrapper.java
    jmeter/trunk/src/components/org/apache/jmeter/timers/SyncTimer.java.tmp
    jmeter/trunk/src/components/org/apache/jmeter/timers/SyncTimer.java.tmp2
Modified:
    jmeter/trunk/src/components/org/apache/jmeter/timers/SyncTimer.java

Modified: jmeter/trunk/src/components/org/apache/jmeter/timers/SyncTimer.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/timers/SyncTimer.java?rev=1205992&r1=1205991&r2=1205992&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/timers/SyncTimer.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/timers/SyncTimer.java Thu Nov 24 22:00:55
2011
@@ -20,6 +20,7 @@ package org.apache.jmeter.timers;
 
 import java.io.Serializable;
 import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
 
 import org.apache.jmeter.engine.event.LoopIterationEvent;
 import org.apache.jmeter.testbeans.TestBean;
@@ -35,6 +36,71 @@ import org.apache.jmeter.threads.JMeterC
  *
  */
 public class SyncTimer extends AbstractTestElement implements Timer, Serializable, TestBean,
TestListener, ThreadListener {
+	
+	/**
+	 * Wrapper to {@link CyclicBarrier} to allow lazy init of CyclicBarrier when SyncTimer is
configured with 0
+	 */
+	private static final class BarrierWrapper implements Cloneable {
+		private CyclicBarrier barrier;
+
+		/**
+		 * 
+		 */
+		public BarrierWrapper() {
+			this.barrier = null;
+		}
+		
+		/**
+		 * @param parties Number of parties
+		 */
+		public BarrierWrapper(int parties) {
+			this.barrier = new CyclicBarrier(parties);
+		}
+		
+		/**
+		 * Synchronized is required to ensure CyclicBarrier is initialized only once per Thread
Group
+		 * @param parties Number of parties
+		 */
+		public synchronized void setup(int parties) {
+			if(this.barrier== null) {
+				this.barrier = new CyclicBarrier(parties);
+			}
+		}
+		
+		/**
+		 * @see CyclicBarrier#await()
+		 * @return int 
+		 * @throws InterruptedException
+		 * @throws BrokenBarrierException
+		 * @see java.util.concurrent.CyclicBarrier#await()
+		 */
+		public int await() throws InterruptedException, BrokenBarrierException {
+			return barrier.await();
+		}
+
+		/**
+		 * @see java.util.concurrent.CyclicBarrier#reset()
+		 */
+		public void reset() {
+			barrier.reset();
+		}
+
+		/**
+		 * @see java.lang.Object#clone()
+		 */
+		@Override
+		protected Object clone()  {
+			BarrierWrapper barrierWrapper=  null;
+			try {
+				barrierWrapper = (BarrierWrapper) super.clone();
+				barrierWrapper.barrier = this.barrier;
+			} catch (CloneNotSupportedException e) {
+				//Cannot happen
+			}
+			return barrierWrapper;
+		}	
+	}
+	
     private static final long serialVersionUID = 2;
     
     private BarrierWrapper barrier;



Mime
View raw message