⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 counterthread.java

📁 Python Development Environment (Python IDE plugin for Eclipse). Features editor, code completion, re
💻 JAVA
字号:
package org.python.pydev.utils;

import org.python.pydev.core.log.Log;

/**
 * This is an auxiliary class for things that require callbacks at some interval.
 * 
 * It allows you to specify the number of times that the callback should be called.  
 *
 */
public class CounterThread extends Thread{
	private ICallback callback;
	private int elapseTime;
	private int stopWhenReaches;

	/**
	 * @param callback the callback that should be called whenever the time elapses (it passes an int, that
	 * says which call is this one).
	 * @param elapseTime this is the millis that should elapse between the calls
	 * @param stopWhenReaches this is the number of times that it should be called
	 */
	public CounterThread(ICallback callback, int elapseTime, int stopWhenReaches){
		this.callback      = callback;       
		this.elapseTime    = elapseTime;    
		this.stopWhenReaches = stopWhenReaches;
        setName("Callback (CounterThread)");
	}
	
	@Override
	public void run() {
		try {
			for (int i = 0; i < stopWhenReaches; i++) {
				try {
					sleep(elapseTime);
					callback.call(i);
				} catch (Exception e) {
					Log.log(e);
					return;
				}
			}
			
		} catch (Exception e) {
			Log.log(e);
			return;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -