We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import net.jodah.expiringmap.ExpirationPolicy; import net.jodah.expiringmap.ExpiringMap; import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.stream.IntStream; public class Main { public static void main(String[] args) { Data data = new Data(); ExecutorService service = Executors.newFixedThreadPool(5); IntStream.range(0, 1000) .forEach(count -> service.submit(data::incrementBy)); } public static class Data { private Map<Integer, Integer> map; public Data() { // this.map = new ConcurrentHashMap<>(); this.map = ExpiringMap.builder() .expiration(100, TimeUnit.MINUTES) .expirationPolicy(ExpirationPolicy.CREATED).build(); this.map.put(1, 0); } public void incrementBy() { this.map.computeIfPresent(1, (key, old) -> { System.out.println(old + 1); return old + 1; }); } } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: