Mercurial > dive4elements > river
annotate flys-backend/src/main/java/de/intevation/flys/utils/EpsilonComparator.java @ 5779:ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
XML DOM is not thread safe. Therefore the old implementation only allowed one thread
to use the builder at a time. As the complexity of the configuration
has increased over time this has become a bottleneck of the whole application
because it took quiet some time to build a result. Furthermore the builder code path
is visited very frequent. So many concurrent requests were piled up
resulting in long waits for the users.
To mitigate this problem a round robin pool of builders is used now.
Each of the pooled builders has an independent copy of the XML template
and can be run in parallel.
The number of builders is determined by the system property
'flys.datacage.pool.size'. It defaults to 4.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sun, 21 Apr 2013 12:48:09 +0200 |
parents | ce6b9945bf8e |
children |
rev | line source |
---|---|
4742 | 1 package de.intevation.flys.utils; |
4732
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.util.Comparator; |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
4742 | 5 /** Comparator with some tolerance (epsilon). */ |
4732
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 public class EpsilonComparator implements Comparator<Double> |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 { |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 public static final double EPSILON = 1e-4; |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 |
4742 | 10 /** Ready-made comparator with 1e-4 tolerance. */ |
4732
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 public static final EpsilonComparator CMP = new EpsilonComparator(EPSILON); |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 private double epsilon; |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 public EpsilonComparator(double epsilon) { |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 this.epsilon = epsilon; |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 } |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 @Override |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 public int compare(Double a, Double b) { |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 double diff = a - b; |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 if (diff < -epsilon) return -1; |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 if (diff > epsilon) return +1; |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 return 0; |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 } |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 } |
7fdddc6ba296
Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
Sascha Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |