All Downloads are FREE. Search and download functionalities are using the official Maven repository.

space.chensheng.wsmessenger.common.util.LoopChecker Maven / Gradle / Ivy

The newest version!
package space.chensheng.wsmessenger.common.util;

public abstract class LoopChecker {
	private long timeoutMillis;
	
	public LoopChecker(long timeoutMillis) {
		this.timeoutMillis = timeoutMillis;
	}
	
	public boolean check() {
		long startTime = System.currentTimeMillis();
		while(true) {
			if(System.currentTimeMillis() - startTime > timeoutMillis) {
				break;
			}
			
			if(condition()) {
				return true;
			}
		}
		return false;
	}
	
	protected abstract boolean condition();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy