Class ThroughputControl
java.lang.Object
org.jpos.util.ThroughputControl
ThroughputControl limits the throughput
of a process to a maximum number of transactions in
a given period of time.
As an example, the following code will cap the transaction count
at 15 every second (a.k.a. 15 TPS).
ThroughputControl throughput = new ThroughputControl(15, 1000);
while (isConditionTrue()) {
throughput.control();
// Do stuff.
}
-
Constructor Summary
ConstructorsConstructorDescriptionThroughputControl(int[] maxTransactions, int[] periodInMillis) ThroughputControl(int maxTransactions, int periodInMillis) -
Method Summary
-
Constructor Details
-
ThroughputControl
- Parameters:
maxTransactions- Transaction count threshold.periodInMillis- Time window, expressed in milliseconds.
-
ThroughputControl
- Parameters:
maxTransactions- An array with transaction count thresholds.periodInMillis- An array of time windows, expressed in milliseconds.
-
-
Method Details
-
control
This method should be called on every transaction. It will pause the thread for a while when the threshold is reached in order to control the process throughput.- Returns:
- Returns sleep time in milliseconds when threshold is reached. Otherwise, zero.
-
toString
-