List of usage examples for java.util TimerTask cancel
public boolean cancel()
From source file:MyTimerTask.java
public static void main(String[] args) { TimerTask task = new MyTimerTask(); Timer timer = new Timer(); // scheduling the task timer.scheduleAtFixedRate(task, new Date(), 1000); // cancelling the task System.out.println("cancelling task: " + task.cancel()); }
From source file:HRTimer.java
/** * Cancels a regsitered task//from w w w .ja v a 2 s .c o m * * @param task * the task to be cancelled */ public void cancelTask(TimerTask task) { --numRepeatTasks; task.cancel(); }
From source file:edu.missouri.bas.service.SensorService.java
public static void CancelTask(TimerTask tTask) { if (tTask != null) tTask.cancel(); }
From source file:edu.caltechUcla.sselCassel.projects.jMarkets.server.control.JMTimer.java
/** Terminate the timer for the given session */ public void terminateSession(int sessionId) { TimerTask task = (TimerTask) sessionTasks.get(new Integer(sessionId)); if (task == null) { log.warn("Could not terminate JM timer for session " + sessionId + " -- no timer exists for that session!"); return;/* w ww .j a va2 s.c o m*/ } task.cancel(); log.debug("Timer for session " + sessionId + " has been canceled"); }
From source file:org.opcfoundation.ua.transport.https.HttpsClient.java
private void cancelTimeoutPendingRequestTask() { TimerTask task = timeoutPendingRequestsTask.getAndSet(null); if (task != null) { task.cancel(); }// w w w . j a va2s .c om }
From source file:org.opcfoundation.ua.transport.https.HttpsClient.java
/** * Sets new Timer Task that timeouts pending requests. * If task already exists but is too far in the future, it is canceled and new task assigned *//*w ww . j a va 2 s .c om*/ private void scheduleTimeoutRequestsTimer() { HttpsClientPendingRequest nextRequest = _getNextTimeoutingPendingRequest(); // Cancel task if (nextRequest == null) { cancelTimeoutPendingRequestTask(); } else { TimerTask task = timeoutPendingRequestsTask.get(); // Task does not exists or is not ok if (task == null || task.scheduledExecutionTime() > nextRequest.timeoutTime) { cancelTimeoutPendingRequestTask(); // Create a new task task = TimerUtil.schedule(timer, timeoutRun, executor, nextRequest.timeoutTime); if (!timeoutPendingRequestsTask.compareAndSet(null, task)) // it was already set task.cancel(); } } }
From source file:sx.blah.discord.handle.impl.obj.Channel.java
@Override public void setTypingStatus(boolean typing) { if (typing) { TimerTask task = new TimerTask() { @Override/*from w ww . j av a 2 s. com*/ public void run() { if (!isPrivate() && isDeleted()) { this.cancel(); return; } try { Discord4J.LOGGER.trace(LogMarkers.HANDLE, "Sending TypingStatus Keep Alive"); ((DiscordClientImpl) client).REQUESTS.POST .makeRequest(DiscordEndpoints.CHANNELS + getLongID() + "/typing"); } catch (RateLimitException | DiscordException e) { Discord4J.LOGGER.error(LogMarkers.HANDLE, "Discord4J Internal Exception", e); } } }; if (typingTask.compareAndSet(null, task)) { typingTimer.scheduleAtFixedRate(task, 0, TIME_FOR_TYPE_STATUS); } } else { TimerTask oldTask = typingTask.getAndSet(null); if (oldTask != null) { oldTask.cancel(); } } }
From source file:com.thebuzzmedia.exiftool.ExifToolNew3.java
/** * Will attempt 3 times to use the running exif process, and if unable to complete successfully will throw * IOException// w w w .j av a 2 s.c om */ private Map<String, String> processStayOpen(List<String> args) throws IOException { int attempts = 0; while (attempts < 3 && !shuttingDown.get()) { attempts++; // make sure process is started ensureProcessRunning(); TimerTask attemptTimer = null; try { if (timeoutWhenKeepAlive > 0) { attemptTimer = new TimerTask() { @Override public void run() { LOG.warn("Process ran too long closing, max " + timeoutWhenKeepAlive + " mills"); process.close(); } }; cleanupTimer.schedule(attemptTimer, timeoutWhenKeepAlive); } LOG.debug("Streaming arguments to ExifToolNew3 process..."); return ExifToolService.toMap(process.sendArgs(args)); } catch (IOException ex) { if (STREAM_CLOSED_MESSAGE.equals(ex.getMessage()) && !shuttingDown.get()) { // only catch "Stream Closed" error (happens when process // has died) LOG.warn(String.format("Caught IOException(\"%s\"), will restart daemon", STREAM_CLOSED_MESSAGE)); process.close(); } else { throw ex; } } finally { if (attemptTimer != null) attemptTimer.cancel(); } } if (shuttingDown.get()) { throw new IOException("Shutting Down"); } throw new IOException("Ran out of attempts"); }
From source file:com.thebuzzmedia.exiftool.ExifTool.java
/** * Will attempt 3 times to use the running exif process, and if unable to * complete successfully will throw IOException *//*from www.j a va 2 s . c om*/ private Map<String, String> processStayOpen(List<String> args) throws IOException { int attempts = 0; while (attempts < 3 && !shuttingDown.get()) { attempts++; // make sure process is started ensureProcessRunning(); TimerTask attemptTimer = null; try { if (timeoutWhenKeepAlive > 0) { attemptTimer = new TimerTask() { @Override public void run() { log.warn("Process ran too long closing, max " + timeoutWhenKeepAlive + " mills"); process.close(); } }; cleanupTimer.schedule(attemptTimer, timeoutWhenKeepAlive); } log.debug("Streaming arguments to ExifTool process..."); return process.sendArgs(args); } catch (IOException ex) { if (STREAM_CLOSED_MESSAGE.equals(ex.getMessage()) && !shuttingDown.get()) { // only catch "Stream Closed" error (happens when process // has died) log.warn(String.format("Caught IOException(\"%s\"), will restart daemon", STREAM_CLOSED_MESSAGE)); process.close(); } else { throw ex; } } finally { if (attemptTimer != null) attemptTimer.cancel(); } } if (shuttingDown.get()) { throw new IOException("Shutting Down"); } throw new IOException("Ran out of attempts"); }
From source file:com.irets.datadownloader.SearchPropertyServlet.java
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm"); long reqInputArrivalTime = System.currentTimeMillis(); Date resultdate = new Date(reqInputArrivalTime); System.out.println("Calling Me @:" + sdf.format(resultdate) + ", from: " + request.getRemoteAddr() + ", with url> " + request.getRequestURL() + "?" + request.getQueryString()); long startTime = reqInputArrivalTime; WebApplicationContext wac = WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()); SearchService propServices = this.getSearchService(wac); propServices.setContextPath(this.getUrl3(request)); //propServices.setServer(this.getServer(request)); Filter filer = new Filter(); ArrayList<FilterItem> filterItemArrayList = new ArrayList<FilterItem>(1); ArrayList<FilterItem> exactFilterItemArrayList = new ArrayList<FilterItem>(1); ArrayList<FilterItem> multipleFilterItemArrayList = new ArrayList<FilterItem>(1); ArrayList<String> keywordArrayList = new ArrayList<String>(1); Vector<SimpleRange> rangeVector = new Vector<SimpleRange>(1); GeoParameter geoParam = null;//from w ww . ja v a2 s .co m // SimpleRange aRange = new SimpleRange("price_list",null,50000); // filer.setRanges(new SimpleRange[]{aRange}); int start = 0; int limit = -1; // if(request.getParameter("ListingId") != null){ // FilterItem filterItem = new FilterItem(); // filterItem.setField("number_MLS"); // filterItem.setValue(request.getParameter("ListingId")); // filterItemArrayList.add(filterItem); // } if (request.getParameter("ListPrice") != null) { SimpleRange aRange; String listPrice = request.getParameter("ListPrice"); System.out.println("List price is " + listPrice); String min = ""; String max = ""; if (!listPrice.equalsIgnoreCase("No Min-No Max")) { if (listPrice.indexOf(":") != -1) { // System.out.println("listPrice : -->>"+listPrice); min = listPrice.substring(0, listPrice.indexOf(":")); max = listPrice.substring(listPrice.indexOf(":") + 1, listPrice.length()); aRange = new SimpleRange("price_list", min, max); } else if (listPrice.endsWith("+")) { // System.out.println("listPrice +-->>"+listPrice); min = listPrice.substring(0, listPrice.indexOf("+")); aRange = new SimpleRange("price_list", min, null); } else if (listPrice.endsWith("-")) { // System.out.println("listPrice - -->>"+listPrice); max = listPrice.substring(0, listPrice.indexOf("-")); aRange = new SimpleRange("price_list", null, max); } else if (listPrice.length() > 0) { // Exact match.... min = listPrice.substring(0, listPrice.length()); max = min; aRange = new SimpleRange("price_list", min, max); } else { aRange = new SimpleRange("price_list", null, null); } rangeVector.add(aRange); } } if (request.getParameter("Bedrooms") != null) { SimpleRange aRange; String bedrooms = request.getParameter("Bedrooms"); String min = ""; String max = ""; if (!bedrooms.equalsIgnoreCase("No Min-No Max")) { if (bedrooms.indexOf(":") != -1) { // System.out.println("Bedrooms: -->>"+bedrooms); min = bedrooms.substring(0, bedrooms.indexOf(":")); max = bedrooms.substring(bedrooms.indexOf(":") + 1, bedrooms.length()); aRange = new SimpleRange("number_beds_Total", min, max); } else if (bedrooms.endsWith("+")) { // System.out.println("Bedrooms+ -->>"+bedrooms); min = bedrooms.substring(0, bedrooms.indexOf("+")); aRange = new SimpleRange("number_beds_Total", min, null); } else if (bedrooms.endsWith("-")) { // System.out.println("Bedrooms- -->>"+bedrooms); max = bedrooms.substring(0, bedrooms.indexOf("-")); aRange = new SimpleRange("number_beds_Total", null, max); } else if (bedrooms.length() > 0) { // Exact match.... min = bedrooms.substring(0, bedrooms.length()); max = min; aRange = new SimpleRange("number_beds_Total", min, max); } else { aRange = new SimpleRange("number_beds_Total", null, null); } rangeVector.add(aRange); } } if (request.getParameter("FullBathrooms") != null) { SimpleRange aRange; String fullBath = request.getParameter("FullBathrooms"); String min = ""; String max = ""; if (!fullBath.equalsIgnoreCase("No Min-No Max")) { if (fullBath.indexOf(":") != -1) { // System.out.println("FullBathrooms: -->>"+fullBath); min = fullBath.substring(0, fullBath.indexOf(":")); max = fullBath.substring(fullBath.indexOf(":") + 1, fullBath.length()); aRange = new SimpleRange("number_baths_Full", min, max); } else if (fullBath.endsWith("+")) { // System.out.println("FullBathrooms+ -->>"+fullBath); min = fullBath.substring(0, fullBath.indexOf("+")); aRange = new SimpleRange("number_baths_Full", min, null); } else if (fullBath.endsWith("-")) { // System.out.println("FullBathrooms- -->>"+fullBath); max = fullBath.substring(0, fullBath.indexOf("-")); aRange = new SimpleRange("number_baths_Full", null, max); } else if (fullBath.length() > 0) { min = fullBath.substring(0, fullBath.length()); max = min; aRange = new SimpleRange("number_baths_Full", min, max); } else { aRange = new SimpleRange("number_baths_Full", null, null); } rangeVector.add(aRange); } } if (request.getParameter("SqFt") != null) { SimpleRange aRange; String sqFt = request.getParameter("SqFt"); String min = ""; String max = ""; if (!sqFt.equalsIgnoreCase("No Min-No Max")) { if (sqFt.indexOf(":") != -1) { // System.out.println("SqFt: -->>"+sqFt); min = sqFt.substring(0, sqFt.indexOf(":")); max = sqFt.substring(sqFt.indexOf(":") + 1, sqFt.length()); aRange = new SimpleRange("sqft_Structure", min, max); } else if (sqFt.endsWith("+")) { // System.out.println("SqFt+ -->>"+sqFt); min = sqFt.substring(0, sqFt.indexOf("+")); aRange = new SimpleRange("sqft_Structure", min, null); } else if (sqFt.endsWith("-")) { // System.out.println("SqFt- -->>"+sqFt); max = sqFt.substring(0, sqFt.indexOf("-")); aRange = new SimpleRange("sqft_Structure", null, max); } else if (sqFt.length() > 0) { min = sqFt.substring(0, sqFt.length()); max = min; aRange = new SimpleRange("sqft_Structure", min, max); } else { aRange = new SimpleRange("sqft_Structure", null, null); } rangeVector.add(aRange); } } // Date range for the property. if (request.getParameter("Age") != null) { SimpleRange aRange; String age = request.getParameter("Age"); String min = ""; String max = ""; if (!age.equalsIgnoreCase("No Min-No Max")) { if (age.indexOf(":") != -1) { System.out.println("age: -->>" + age); min = age.substring(0, age.indexOf(":")); max = age.substring(age.indexOf(":") + 1, age.length()); aRange = new SimpleRange("date_Listing_Modification", min, max); } else if (age.endsWith("+")) { // System.out.println("SqFt+ -->>"+sqFt); min = age.substring(0, age.indexOf("+")); aRange = new SimpleRange("date_Listing_Modification", min, null); } else if (age.endsWith("-")) { // System.out.println("SqFt- -->>"+sqFt); max = age.substring(0, age.indexOf("-")); aRange = new SimpleRange("date_Listing_Modification", null, max); } else if (age.length() > 0) { min = age.substring(0, age.length()); max = min; aRange = new SimpleRange("date_Listing_Modification", min, max); } else { aRange = new SimpleRange("date_Listing_Modification", null, null); } System.out.println("Range is " + aRange.getMinValue() + ", " + aRange.getMaxValue()); rangeVector.add(aRange); } } // Range for Longitude if (request.getParameter("Longitude") != null) { SimpleRange aRange; String longitude = request.getParameter("Longitude"); System.out.println("Longitude is " + longitude); String min = ""; String max = ""; if (longitude.indexOf(":") != -1) { min = longitude.substring(0, longitude.indexOf(":")); max = longitude.substring(longitude.indexOf(":") + 1, longitude.length()); aRange = new SimpleRange("_long", min, max); } else { aRange = new SimpleRange("_long", null, null); } rangeVector.add(aRange); } // Range for Latitude if (request.getParameter("Latitude") != null) { SimpleRange aRange; String latitude = request.getParameter("Latitude"); System.out.println("Latitude is " + latitude); String min = ""; String max = ""; if (latitude.indexOf(":") != -1) { min = latitude.substring(0, latitude.indexOf(":")); max = latitude.substring(latitude.indexOf(":") + 1, latitude.length()); aRange = new SimpleRange("lat", min, max); } else { aRange = new SimpleRange("lat", null, null); } rangeVector.add(aRange); } // Near by homes // Format required is Latitude,Longitude,distance if (request.getParameter("NBH") != null) { String nbh = request.getParameter("NBH"); String[] s = nbh.split(","); if (s.length == 3) { Float f = Float.valueOf(s[2]); if (f >= 10) // 10 miles radius max s[2] = "10"; else if (f < 0) // if negative distance s[2] = "1"; geoParam = new GeoParameter(s[0], s[1], s[2]); } } else { // City and Zip are optional if NBH is provided. if (request.getParameter("Zip") != null) { FilterItem filterItem = new FilterItem(); filterItem.setField("zipCode"); // remove the space first String inZipcode = request.getParameter("Zip"); StringBuffer zipBuffer = new StringBuffer(); if (inZipcode.indexOf(",") > -1) { StringTokenizer sToken = new StringTokenizer(inZipcode, ","); while (sToken.hasMoreElements()) { String object = (String) sToken.nextElement(); zipBuffer.append("'"); zipBuffer.append(object); zipBuffer.append("'"); if (sToken.countTokens() > 0) zipBuffer.append(","); } } else { zipBuffer.append("'"); zipBuffer.append(inZipcode); zipBuffer.append("'"); } //System.out.println(zipBuffer.toString()); filterItem.setValue(zipBuffer.toString()); multipleFilterItemArrayList.add(filterItem); } if (request.getParameter("City") != null) { FilterItem filterItem = new FilterItem(); filterItem.setField("name_City"); String cityList = request.getParameter("City"); StringBuffer cityMod = new StringBuffer(); if (cityList.indexOf(",") > -1) { StringTokenizer sToken = new StringTokenizer(cityList, ","); while (sToken.hasMoreElements()) { String object = (String) sToken.nextElement(); cityMod.append("'"); cityMod.append(getCity(object)); cityMod.append("'"); if (sToken.countTokens() > 0) cityMod.append(","); } } else { cityMod.append("'"); cityMod.append(getCity(cityList)); cityMod.append("'"); } filterItem.setValue(cityMod.toString()); multipleFilterItemArrayList.add(filterItem); } } // Status of property, link Active or Pending // For backward compatibility, Status=A. we added extra checks // for Status=ACTIVE or PENDING /* * if(request.getParameter("Status") != null && (request.getParameter("Status").equalsIgnoreCase("ACTIVE")|| request.getParameter("Status").equalsIgnoreCase("PENDING"))){ FilterItem filterItem = new FilterItem(); filterItem.setField("status_Listing"); filterItem.setValue(request.getParameter("Status")); if (request.getParameter("Status").equalsIgnoreCase("PENDING")){ filterItem.setValue(propServices.getPendingStatus()); } filterItemArrayList.add(filterItem); } */ if (request.getParameter("Status") != null && (request.getParameter("Status").equalsIgnoreCase("ACTIVE") || request.getParameter("Status").equalsIgnoreCase("PENDING"))) { FilterItem filterItem = new FilterItem(); filterItem.setField("status_Listing"); StringBuffer statusMod = new StringBuffer(); String statusList = null; if (request.getParameter("Status").equalsIgnoreCase("ACTIVE")) { statusList = propServices.getActiveStatus(); } else if (request.getParameter("Status").equalsIgnoreCase("PENDING")) { statusList = propServices.getPendingStatus(); } if (statusList.indexOf(",") > -1) { StringTokenizer sToken = new StringTokenizer(statusList, ","); while (sToken.hasMoreElements()) { String object = (String) sToken.nextElement(); statusMod.append("'"); statusMod.append(object); statusMod.append("'"); if (sToken.countTokens() > 0) statusMod.append(","); } } else { statusMod.append("'"); statusMod.append(statusList); statusMod.append("'"); } System.out.println("Status query..: " + statusMod.toString()); filterItem.setValue(statusMod.toString()); multipleFilterItemArrayList.add(filterItem); } if (request.getParameter("ListingId") != null) { FilterItem filterItem = new FilterItem(); filterItem.setField("number_MLS"); String listingId = request.getParameter("ListingId"); String mlsNumberPrefix = propServices.getMlsNumberPrefix(); StringBuffer listingIdList = new StringBuffer(); if (listingId.indexOf(",") > -1) { StringTokenizer sToken = new StringTokenizer(listingId, ","); while (sToken.hasMoreElements()) { String object = (String) sToken.nextElement(); if ((mlsNumberPrefix != null) && (!mlsNumberPrefix.equals("")) && (!object.contains(mlsNumberPrefix))) { listingIdList.append("'" + mlsNumberPrefix); } else { listingIdList.append("'"); } listingIdList.append(object); listingIdList.append("'"); if (sToken.countTokens() > 0) listingIdList.append(","); } } else { if ((mlsNumberPrefix != null) && (!mlsNumberPrefix.equals("")) && (!listingId.contains(mlsNumberPrefix))) listingIdList.append("'" + mlsNumberPrefix); else listingIdList.append("'"); listingIdList.append(listingId); listingIdList.append("'"); } filterItem.setValue(listingIdList.toString()); multipleFilterItemArrayList.add(filterItem); //System.out.println("got listing id "+ request.getParameter("ListingId")); } if (request.getParameter("ListingAgentLic") != null) { FilterItem filterItem = new FilterItem(); filterItem.setField("listing_license_number"); String listingId = request.getParameter("ListingAgentLic"); if (listingId.indexOf(",") > -1) { StringTokenizer sToken = new StringTokenizer(listingId, ","); while (sToken.hasMoreElements()) { keywordArrayList.add((String) sToken.nextElement()); } } else { keywordArrayList.add(listingId); } //System.out.println("got listing agent lic "+ request.getParameter("ListingAgentLic")); } if (request.getParameter("offset") != null) { start = Integer.parseInt(request.getParameter("offset")); } if (request.getParameter("limit") != null) { limit = Integer.parseInt(request.getParameter("limit")); } String sort = request.getParameter("sort"); if (sort != null) { if (sort.equalsIgnoreCase("City")) { sort = "name_City"; } else if (sort.equalsIgnoreCase("YearBuilt")) { sort = "year_Built"; } else if (sort.equalsIgnoreCase("ListPrice")) { sort = "price_List"; } else if (sort.equalsIgnoreCase("Sqft")) { sort = "sqft_Structure"; } else if (sort.equalsIgnoreCase("LotSqFt")) { sort = "Size_Lot"; } else if (sort.equalsIgnoreCase("Type")) { sort = ""; } else if (sort.equalsIgnoreCase("Bedrooms")) { sort = "number_beds_Total"; } else if (sort.equalsIgnoreCase("FullBathrooms")) { sort = "number_baths_Full"; } else if (sort.equalsIgnoreCase("ExteriorFeatures")) { sort = "type_Property"; } else if (sort.equalsIgnoreCase("none")) { sort = null; } } String sort_direction = request.getParameter("sort_direction"); if (sort_direction != null) { if (sort_direction.equalsIgnoreCase("none")) { sort_direction = null; } else if (sort_direction.equalsIgnoreCase("ASC")) { sort_direction = "asc"; } else { sort_direction = "desc"; } } else { //{TOD: why do we need this?? if (request.getParameter("ListingAgentLic") != null) { sort = "price_List"; sort_direction = "desc"; // with agent listing, they want desc } else { sort_direction = "asc"; // default sorting order } } // Type of property, link Single Family, Townhouse, Condominium if (request.getParameter("ExteriorFeatures") != null) { String param = request.getParameter("ExteriorFeatures"); FilterItem filterItem = new FilterItem(); filterItem.setField("type_Property"); List<ExteriorFeaturesData> extFeatureData = propServices.getExtFeaturesData(); // Getting ExFeatures list from properties files if (extFeatureData != null) { System.out.println("Exterior Features param is " + param); for (ExteriorFeaturesData efd : extFeatureData) { if (efd.getName().equalsIgnoreCase(param)) { filterItem.setValue(efd.getInSearchFields()); break; } } if (filterItem.getValue() != null) { System.out.println("Exterior Features value " + filterItem.getValue()); multipleFilterItemArrayList.add(filterItem); } } else {// Getting ExFeatures list from DB filterItem.setValue(param); System.out.println("Exterior Features (single) " + filterItem.getValue()); filterItemArrayList.add(filterItem); } } // Adding the search parameter for Full Address if (request.getParameter("FullAddress") != null) { FilterItem filterItem = new FilterItem(); filterItem.setField("address_Filtered"); filterItem.setValue(request.getParameter("FullAddress")); filterItemArrayList.add(filterItem); } boolean returnOpenHouseData = false; if (request.getParameter("OpenHouse") != null) { if (request.getParameter("OpenHouse").equals("1")) { returnOpenHouseData = true; } } // Put the keyword search (using it for license id) String[] filterArrayKeyword = new String[keywordArrayList.size()]; filterArrayKeyword = keywordArrayList.toArray(filterArrayKeyword); filer.setKeywords(filterArrayKeyword); // Put range in the filter SimpleRange[] sRangeArray = new SimpleRange[rangeVector.size()]; sRangeArray = rangeVector.toArray(sRangeArray); filer.setRanges(sRangeArray); // Put single value item in the filter with '%value%' FilterItem[] filterArray = new FilterItem[filterItemArrayList.size()]; filterArray = filterItemArrayList.toArray(filterArray); filer.setFilters(filterArray); // Put single value item in the filter, with exact search with 'value' FilterItem[] exactFilterArray = new FilterItem[exactFilterItemArrayList.size()]; exactFilterArray = exactFilterItemArrayList.toArray(exactFilterArray); filer.setExactFilters(exactFilterArray); // Put the multiple values (',' separated) item in the filter. FilterItem[] filterItemA = new FilterItem[multipleFilterItemArrayList.size()]; filterItemA = multipleFilterItemArrayList.toArray(filterItemA); filer.setSearchForFieldItems(filterItemA); //System.out.println("time in making query:"+(new Date().getTime()-startTime)+" msecs"); //System.out.println("limit " + request.getParameter("limit") + ", offset " + // request.getParameter("offset") +", sort " + sort + ", sort direction "+ sort_direction); Object returnObj = null; startTime = new Date().getTime(); // Create a Timer and a TimerTask Timer timer = new Timer(); TimerTask task = new SearchPropertyTimerTask(request, response, this.getOutputType()); // Set timer for 30 sec, method takes args in milliseconds. timer.schedule(task, 30 * 1000); boolean timedoutResponse = true;// Default is timed out response. try { /* for testing of timer functionality. try { Thread.sleep(10000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ Properties prop = propServices.searchForProperties(start, limit, sort, sort_direction, filer, geoParam, returnOpenHouseData); prop.setElapsedTime(BigInteger.valueOf(System.currentTimeMillis() - reqInputArrivalTime)); if (this.getOutputType().equalsIgnoreCase("json")) { returnObj = getJSONReturnObj(prop); } else { returnObj = prop; } } catch (LargeResultSetException e) { Errors errors = new Errors(); com.irets.generated.Error error = new com.irets.generated.Error(); error.setCode(e.getErrorCode()); error.setDescription(e.getMessage()); errors.getError().add(error); errors.setTotalcount(BigInteger.valueOf(e.getTotalCount())); errors.setElapsedtime(BigInteger.valueOf(System.currentTimeMillis() - reqInputArrivalTime)); returnObj = errors; System.out.println(e.getMessage()); } finally { if (task.cancel()) { timedoutResponse = false;// No timeout, send normal response. } } System.out.println("time in database call:" + (new Date().getTime() - startTime) + " msecs"); //startTime = new Date().getTime(); //GSONHelper.serializeToJSON(prop, response.getOutputStream()); if (!timedoutResponse) { if (this.getOutputType().equalsIgnoreCase("json")) { response.setContentType("application/json"); JacksonJSONHelper.serializeToJSON(returnObj, response.getOutputStream(), response); } else { response.setContentType("text/xml"); JAXBHelper.serializeToXML(returnObj, response.getOutputStream()); } } //System.out.println("time in making output:"+(new Date().getTime()-startTime)+" msecs"); System.out.println("Done!!!! elapsed time: " + (System.currentTimeMillis() - reqInputArrivalTime)); }