Source:
public RenderedImageMap produceMap(final WMSMapContent mapContent, final boolean tiled) { this.mapContent = mapContent; final GetMapRequest request = mapContent.getRequest(); RenderedImageMap map = null; this.map = null; int maxRenderingTime = wms.getMaxRenderingTime() * 1000; int localMaxRenderingTime = 0; Object timeoutOption = request.getFormatOptions().get("timeout"); if (timeoutOption != null) { try { localMaxRenderingTime = Integer.parseInt(timeoutOption.toString()); } catch (NumberFormatException e) { LOGGER.log(Level.WARNING,"Could not parse format_option \"timeout\": "+timeoutOption, e); } } if (maxRenderingTime == 0) { maxRenderingTime = localMaxRenderingTime; } else if (localMaxRenderingTime != 0) { maxRenderingTime = Math.min(maxRenderingTime, localMaxRenderingTime); } Thread produceMapThread = new Thread(new Runnable() { @Override public void run() { InternalTimeoutOutputFormat.this.map = InternalTimeoutOutputFormat.super.produceMap(mapContent, tiled); } }); try { produceMapThread.start(); produceMapThread.join(maxRenderingTime); } catch (InterruptedException e) { LOGGER.log(Level.FINE, "Rendering was interrupted", e); } finally { if (produceMapThread.isAlive()) { LOGGER.log(Level.FINE,"Renderer timed out. Returning partial image"); map = buildMap(mapContent, preparedImage); new Thread(new StopRenderingRunnable(produceMapThread, renderer, graphic)).start(); } else { map = this.map; } this.mapContent = null; this.renderer = null; this.graphic = null; this.preparedImage = null; this.map = null; } return map; }

Target:
public RenderedImageMap produceMap(final WMSMapContent mapContent, final boolean tiled) { this.mapContent = mapContent; final GetMapRequest request = mapContent.getRequest(); RenderedImageMap map = null; this.map = null; int maxRenderingTime = wms.getMaxRenderingTime() * 1000; int localMaxRenderingTime = 0; Object timeoutOption = request.getFormatOptions().get("timeout"); if (timeoutOption != null) { try { localMaxRenderingTime = Integer.parseInt(timeoutOption.toString()); } catch (NumberFormatException e) { LOGGER.log(Level.WARNING,"Could not parse format_option \"timeout\": "+timeoutOption, e); } } if (maxRenderingTime == 0) { maxRenderingTime = localMaxRenderingTime; } else if (localMaxRenderingTime != 0) { maxRenderingTime = Math.min(maxRenderingTime, localMaxRenderingTime); } Thread produceMapThread = new Thread(new Runnable() { @Override public void run() { try { InternalTimeoutOutputFormat.this.map = InternalTimeoutOutputFormat.super.produceMap(mapContent, tiled); } catch (ServiceException e) { exception = e; } catch (Throwable t) { LOGGER.log(Level.FINER, "produceMap() threw an unexpected error", t); } } }); try { produceMapThread.start(); produceMapThread.join(maxRenderingTime); } catch (InterruptedException e) { LOGGER.log(Level.FINE, "Rendering was interrupted", e); } if (produceMapThread.isAlive()) { LOGGER.log(Level.FINE,"Renderer timed out. Returning partial image"); map = buildMap(mapContent, preparedImage); new Thread(new StopRenderingRunnable(produceMapThread, renderer, graphic)).start(); } else if (this.map == null) { map = buildMap(mapContent, preparedImage); } else { map = this.map; } this.mapContent = null; this.renderer = null; this.graphic = null; this.preparedImage = null; this.map = null; if (exception != null) { ServiceException e = exception; exception = null; throw e; } return map; }