Skip to content

Commit 8cf36b0

Browse files
author
Peter
committed
fixed serious problem in GHWorker if work is already done before wait is called
1 parent 89c0b69 commit 8cf36b0

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

core/src/main/java/com/graphhopper/storage/index/LocationIndexTree.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@
3030
import gnu.trove.list.array.TIntArrayList;
3131
import gnu.trove.procedure.TIntProcedure;
3232
import gnu.trove.set.hash.TIntHashSet;
33-
import java.util.ArrayList;
34-
import java.util.Arrays;
35-
import java.util.Collection;
36-
import java.util.List;
33+
import java.util.*;
3734
import org.slf4j.Logger;
3835
import org.slf4j.LoggerFactory;
3936

@@ -60,7 +57,7 @@ public class LocationIndexTree implements LocationIndex
6057
private byte[] shifts;
6158
// convert spatial key to index for subentry of current depth
6259
private long[] bitmasks;
63-
SpatialKeyAlgo keyAlgo;
60+
protected SpatialKeyAlgo keyAlgo;
6461
private int minResolutionInMeter = 500;
6562
private double deltaLat;
6663
private double deltaLon;
@@ -551,7 +548,7 @@ TIntArrayList getEntries()
551548
return new TIntArrayList(entries);
552549
}
553550

554-
// fillIDs according to how they are stored
551+
// fillIDs according to how they are stored
555552
void fillIDs( long keyPart, int intIndex, TIntHashSet set, int depth )
556553
{
557554
long pointer = (long) intIndex << 2;
@@ -623,7 +620,7 @@ public QueryResult findClosest( final double queryLat, final double queryLon,
623620
final EdgeFilter edgeFilter )
624621
{
625622
final TIntHashSet storedNetworkEntryIds = findNetworkEntries(queryLat, queryLon);
626-
final QueryResult closestMatch = new QueryResult(queryLat, queryLon);
623+
final QueryResult closestMatch = new QueryResult(queryLat, queryLon);
627624
if (storedNetworkEntryIds.isEmpty())
628625
return closestMatch;
629626

core/src/main/java/com/graphhopper/util/Measurement.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void start( CmdArgs args )
111111
{
112112
maxNode = g.getNodes();
113113
printGraphDetails(g);
114-
printLocation2IDQuery(g, hopper.getLocationIndex(), count);
114+
printLocationIndexQuery(g, hopper.getLocationIndex(), count);
115115

116116
// Route via dijkstrabi. Normal routing takes a lot of time => smaller query number than CH
117117
// => values are not really comparable to routingCH as e.g. the mean distance etc is different
@@ -158,7 +158,7 @@ private void printGraphDetails( GraphStorage g )
158158
put("graph.encoder", g.getEncodingManager().getSingle().toString());
159159
}
160160

161-
private void printLocation2IDQuery( Graph g, final LocationIndex idx, int count )
161+
private void printLocationIndexQuery( Graph g, final LocationIndex idx, int count )
162162
{
163163
count *= 2;
164164
final BBox bbox = g.getBounds();

web/src/main/java/com/graphhopper/http/GHThreadPool.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
*/
3535
public class GHThreadPool
3636
{
37-
private Logger logger = LoggerFactory.getLogger(getClass());
37+
private final Logger logger = LoggerFactory.getLogger(getClass());
3838
private final ExecutorService service;
3939
private final int threads;
40-
private BlockingQueue<GHWorker> resolverQueue;
40+
private final BlockingQueue<GHWorker> resolverQueue;
4141

4242
public GHThreadPool( int queueSize, int threads )
4343
{
@@ -141,7 +141,8 @@ public void waitFor( List<GHWorker> workers, long timeOutInMillis )
141141
long tmp = System.currentTimeMillis();
142142
synchronized (w)
143143
{
144-
w.wait(timeOutInMillis);
144+
if (w.isAlive())
145+
w.wait(timeOutInMillis);
145146
}
146147
remainingTimeout -= (System.currentTimeMillis() - tmp);
147148
if (remainingTimeout < 10)
@@ -157,8 +158,9 @@ public void waitFor( List<GHWorker> workers, long timeOutInMillis )
157158

158159
public static abstract class GHWorker implements Runnable
159160
{
160-
private long maxLiveTimeInMillis = 5000;
161-
private long startTime = -1;
161+
private final long maxLiveTimeInMillis;
162+
private volatile long startTime = -1;
163+
private volatile boolean alive = true;
162164

163165
public GHWorker( long maxLiveTimeInMillis )
164166
{
@@ -174,24 +176,29 @@ private GHWorker doEnqueue()
174176
private boolean isTimedOut()
175177
{
176178
if (startTime < 0)
177-
{
178179
throw new IllegalStateException("Call doEnqueue before");
179-
}
180+
180181
return (System.currentTimeMillis() - startTime) > maxLiveTimeInMillis;
181182
}
182183

183184
public abstract String getName();
184185

186+
public boolean isAlive()
187+
{
188+
return alive;
189+
}
190+
185191
@Override
186192
public String toString()
187193
{
188194
return getName();
189195
}
190196

191197
private void finish()
192-
{
198+
{
193199
synchronized (this)
194200
{
201+
alive = false;
195202
notifyAll();
196203
}
197204
}

0 commit comments

Comments
 (0)