mkodekar / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

"Throttle" for slowing down rapidly submitted Runnables #1856

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
From the mailing-list:

Especially in GUI-applications I often find myself in the need for a throttle 
which executes a Runnable only after a certain time has passed and only the 
last Runnable that has been scheduled.

Example: In SWT, when the user resizes a window or a table-column I store that 
information.
SWT has a Listener for the resize-event which fires basically for every pixel 
that is moved, so one resize fires potentially hundreds of events, saving that 
every time would be slow and I'm only interested in the last value anyway.

I implemented an Executor [0] that can give me an instance of Throttle [1] with 
a specified timeout..

When a Runnable is submitted to/via the Throttle it is only executed after the 
timeout has passed. Within this time, every newly submitted Runnable replaces 
the one waiting.

[0] 
https://github.com/fab1an/appkit/blob/master/src/main/java/org/appkit/concurrent
/SmartExecutor.java
[1] https://fab1an.github.io/appkit/javadoc/org/appkit/concurrent/Throttle.html

Original issue reported on code.google.com by fabian.z...@gmail.com on 24 Sep 2014 at 7:13

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<issue id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:08

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:17

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:07