Changeset 11438 in josm for trunk/src/org
- Timestamp:
- 2017-01-07T09:44:59+01:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/cache/HostLimitQueue.java
r11381 r11438 9 9 import java.util.concurrent.LinkedBlockingDeque; 10 10 import java.util.concurrent.Semaphore; 11 import java.util.concurrent.ThreadPoolExecutor; 11 12 import java.util.concurrent.TimeUnit; 12 13 … … 32 33 private final Map<String, Semaphore> hostSemaphores = new ConcurrentHashMap<>(); 33 34 private final int hostLimit; 35 36 private ThreadPoolExecutor executor; 37 38 private int corePoolSize; 39 40 private int maximumPoolSize; 34 41 35 42 /** … … 93 100 } 94 101 102 /** 103 * Set the executor for which this queue works. It's needed to spawn new threads. 104 * See: http://stackoverflow.com/questions/9622599/java-threadpoolexecutor-strategy-direct-handoff-with-queue# 105 * 106 * @param executor 107 */ 108 109 public void setExecutor(ThreadPoolExecutor executor) { 110 this.executor = executor; 111 this.maximumPoolSize = executor.getMaximumPoolSize(); 112 this.corePoolSize = executor.getCorePoolSize(); 113 } 114 115 @Override 116 public boolean offer(Runnable e) 117 { 118 if (super.offer(e) == false) 119 { 120 return false; 121 } 122 123 if (executor != null) { 124 // See: http://stackoverflow.com/questions/9622599/java-threadpoolexecutor-strategy-direct-handoff-with-queue# 125 // force spawn of a thread if not reached maximum 126 int currentPoolSize = executor.getPoolSize(); 127 if (currentPoolSize < maximumPoolSize 128 && currentPoolSize >= corePoolSize) 129 { 130 executor.setCorePoolSize(currentPoolSize + 1); 131 executor.setCorePoolSize(corePoolSize); 132 } 133 } 134 return true; 135 } 136 95 137 private Semaphore getSemaphore(JCSCachedTileLoaderJob<?, ?> job) { 96 138 String host; -
trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoader.java
r10877 r11438 78 78 */ 79 79 public static ThreadPoolExecutor getNewThreadPoolExecutor(String nameFormat, int workers) { 80 return new ThreadPoolExecutor( 81 workers, // keep the thread number constant 80 HostLimitQueue workQueue = new HostLimitQueue(HOST_LIMIT.get().intValue()); 81 ThreadPoolExecutor executor = new ThreadPoolExecutor( 82 0, // 0 so for unused thread pools threads will eventually die, freeing also the threadpool 82 83 workers, // do not this number of threads 83 30 , // keepalive for thread84 300, // keepalive for thread 84 85 TimeUnit.SECONDS, 85 new HostLimitQueue(HOST_LIMIT.get().intValue()),86 workQueue, 86 87 Utils.newThreadFactory(nameFormat, Thread.NORM_PRIORITY) 87 88 ); 89 workQueue.setExecutor(executor); 90 return executor; 88 91 } 89 92 -
trunk/src/org/openstreetmap/josm/data/imagery/WMSCachedTileLoader.java
r8734 r11438 10 10 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener; 11 11 import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry; 12 import org.openstreetmap.josm.data.preferences.IntegerProperty; 12 13 13 14 /** … … 20 21 public class WMSCachedTileLoader extends TMSCachedTileLoader { 21 22 23 /** 24 * overrides the THREAD_LIMIT in superclass, as we want to have separate limit and pool for WMS 25 */ 26 public static final IntegerProperty THREAD_LIMIT = new IntegerProperty("imagery.wms.loader.maxjobs", 3); 22 27 /** 23 28 * Creates a TileLoader with separate WMS downloader. -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/WMSSettingsPanel.java
r11287 r11438 13 13 import javax.swing.SpinnerNumberModel; 14 14 15 import org.openstreetmap.josm.data.imagery.WMSCachedTileLoader Job;15 import org.openstreetmap.josm.data.imagery.WMSCachedTileLoader; 16 16 import org.openstreetmap.josm.gui.layer.WMSLayer; 17 17 import org.openstreetmap.josm.tools.GBC; … … 49 49 add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL)); 50 50 JLabel labelSimConn = new JLabel(tr("Simultaneous connections:")); 51 int threadLimitValue = Utils.clamp(WMSCachedTileLoader Job.THREAD_LIMIT.get(), THREADS_MIN, THREADS_MAX);51 int threadLimitValue = Utils.clamp(WMSCachedTileLoader.THREAD_LIMIT.get(), THREADS_MIN, THREADS_MAX); 52 52 spinSimConn = new JSpinner(new SpinnerNumberModel(threadLimitValue, THREADS_MIN, THREADS_MAX, 1)); 53 53 labelSimConn.setLabelFor(spinSimConn); … … 71 71 public void loadSettings() { 72 72 this.autozoomActive.setSelected(WMSLayer.PROP_DEFAULT_AUTOZOOM.get()); 73 this.spinSimConn.setValue(WMSCachedTileLoader Job.THREAD_LIMIT.get());73 this.spinSimConn.setValue(WMSCachedTileLoader.THREAD_LIMIT.get()); 74 74 this.tileSize.setValue(WMSLayer.PROP_IMAGE_SIZE.get()); 75 75 } … … 81 81 public boolean saveSettings() { 82 82 WMSLayer.PROP_DEFAULT_AUTOZOOM.put(this.autozoomActive.isSelected()); 83 WMSCachedTileLoader Job.THREAD_LIMIT.put((Integer) spinSimConn.getModel().getValue());83 WMSCachedTileLoader.THREAD_LIMIT.put((Integer) spinSimConn.getModel().getValue()); 84 84 WMSLayer.PROP_IMAGE_SIZE.put((Integer) this.tileSize.getModel().getValue()); 85 85
Note:
See TracChangeset
for help on using the changeset viewer.