public void run() {

while (true) {
try {
current = System.currentTimeMillis();
time_passed = current – last_check;
last_check = current;
allowance += time_passed * (getRate() / getPer());
if (allowance > getRate()) {
allowance = getRate();
}
if (allowance < 1000) {
} else {
q.put(new SimpleDateFormat(“dd/mm/yy hh:MM:ss:SSSS”).format(new Date()));
allowance -= 1000;
}

} catch (InterruptedException e) {
e.printStackTrace();
}

}
}

from http://stackoverflow.com/questions/667508/whats-a-good-rate-limiting-algorithm