public void run() {

			while(!killed()) {

				long nextFlushLocal = nextFlush.get();

				long currentTime = System.currentTimeMillis();
				
				//System.out.println("next flush local: " + nextFlushLocal + " currentTime " + currentTime);

				if(nextFlushLocal != 0 && nextFlushLocal < currentTime + 2) {

					//if(lock.tryLock()) {
					lock.lock(); {
						try {
							flush();
						} catch (IOException e) {
						} finally {
							lock.unlock();
						}
					} 

				}

				synchronized(syncObj) {
					nextFlushLocal = nextFlush.get();
					currentTime = System.currentTimeMillis();

					long delay = Math.max(2L, Math.min(maxLatency, nextFlushLocal - currentTime));
					//System.out.println("Timer sleeping for " + delay + " at " + System.currentTimeMillis());
					try {
						if(nextFlushLocal == 0 ) {
							//System.out.println("Waiting 500");
							syncObj.wait(500);
						} else {
							//System.out.println("Waiting " + delay);
							syncObj.wait(delay);
						} 
						//System.out.println("Timer wake up" + System.currentTimeMillis());
					} catch (InterruptedException ie) {
						kill();
						continue;
					}
				}
			}
		}