I’d use a ring buffer of timestamps with a fixed size of M. Each time the method is called, you check the oldest entry, and if it’s less than N seconds in the past, you execute and add another entry, otherwise you sleep for the time difference.
More Related Contents:
- Java – public class constructor [duplicate]
- What’s the best way to share data between activities?
- How to find a Java Memory Leak
- Java Array, Finding Duplicates
- Is System.nanoTime() completely useless?
- Call “java -jar MyFile.jar” with additional classpath option
- When do you use map vs flatMap in RxJava?
- What does Class mean in Java?
- Apache POI error loading XSSFWorkbook class
- Java 8 default methods as traits : safe?
- Best practice for passing many arguments to method?
- java.net.SocketException: socket failed: EPERM (Operation not permitted)
- Jar Mismatch Found 2 versions of android-support-v4.jar in the dependency list
- How to scan a folder in Java?
- Creating zip archive in Java
- Fast CSV parsing
- Can we make object as key in map when using JSON?
- LinkedHashMap in .NET
- Warning message “uses or overrides a deprecated API” encountered during code compilation
- CubicCurve JavaFX
- Maven surefire could not find ForkedBooter class
- Final arguments in interface methods – what’s the point?
- Manually call Spring Annotation Validation
- What is the difference between Transaction-scoped Persistence context and Extended Persistence context?
- casting Arrays.asList causing exception: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList
- In Java, how do I dynamically determine the type of an array?
- Jackson ObjectMapper DeserializationConfig.Feature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT
- Name attribute in @Entity and @Table
- Breaking down RSA/ECB/OAEPWithSHA-256AndMGF1Padding
- Converting an int array to a String array