if(delaySeconds >= (pollFreq * 1000)) { //allow for 2 second network delay, delaySeconds = 2000 if(y == 5) { //insert the 5th value from the array Map lastPerfIdInsertMap = (Map) sc.getAttribute("lastPerfIdInsertMap"); //get reference as it maybe required for data inserts > 15 seconds apart long lts = new Long((String) lastPerfIdInsertMap.get(clientId + "&" + perfId)); //get the last timestamp from the key; key combo -->> clientId&perfId = timestamp if((lts + (pollFreq * 1000)) < currentTime ) { //last timestamp + poll frequency(seconds) < current time lastPerfIdInsertMap.put(clientId + "&" + perfId, currentTime); //update the static threadsafe map that holds the timestamp value of when data was last inserted sc.setAttribute("lastPerfIdInsertMap", lastPerfIdInsertMap); //reinstate the Map into the servlet context ready for use by another thread PerformanceVO ppvvoo = new PerformanceVO(); //create a new pvo object to insert!!! A must to make new!! ppvvoo.setPerfId(perfId); ppvvoo.setTagId(pVO.getTagId()); ppvvoo.setTimestamp(currentTime); ppvvoo.setMeasuredValue(dataArray[y]); pService.insertTemperature(ppvvoo); //insert the data and bail } } }