Throttle: one submission every , won’t start a new task until elapsed time has passed.
Debounce: one submission every , will cancel all pending tasks to schedule a new one.

Both are instantiated with and the only public API is attempt(Runnable), where Runnable is the task to be queued.

In practical terms:

In the above example (Debounce), System.out will print “2” after 250 milliseconds, and the first 2 calls will never happen.

In the above example (Throttle), System.out will print “0” immediately and discard the subsequent calls.

Usage: