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

com.yuweix.kuafu.schedule.base.AbstractThreadPoolPageTask Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package com.yuweix.kuafu.schedule.base;


import java.util.List;
import java.util.concurrent.ExecutorService;


/**
 * @author yuwei
 */
public abstract class AbstractThreadPoolPageTask extends AbstractThreadPoolTask {
	private static final int DEFAULT_MAX_TIMES = -1;


	@Override
	protected void executeInThreadPool(ExecutorService executor) {
		int pageNo = 1;
		int pageSize = getPageSize();

		int times = 0;
		int maxTimes = getMaxTimes();

		while (true) {
			boolean stop = maxTimes != DEFAULT_MAX_TIMES && ++times > maxTimes;
			if (stop) {
				break;
			}

			List taskList = findTaskList(pageNo++, pageSize);
			if (taskList == null || taskList.size() <= 0) {
				break;
			}
			executeInThreadPool(executor, taskList);
		}
	}

	@Override
	protected List findTaskList() {
		throw new RuntimeException("Not Supported.");
	}
	protected abstract List findTaskList(int pageNo, int pageSize);

	protected int getMaxTimes() {
		return DEFAULT_MAX_TIMES;
	}
	protected int getPageSize() {
		return 10;
	}
}






© 2015 - 2024 Weber Informatics LLC | Privacy Policy