there a way I can limit the function so it can be called only say, 1 time in 50ms ?
There are 2 techniques for limiting function calling rate: debouncing and throttling. Unfortunately there is no easy and straightforward way to implement such functionality in Java. You may want to take a look at this library https://github.com/ThomasGirard/JDebounce or RateLimiter class from Guava. (Javascript guys are laughing at us because they have _.throttle and _.debounce 😄)
Обсуждают сегодня