Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SynchroExample {
- public final AtomicInteger integer = new AtomicInteger(0);
- private ExecutorService service = Executors.newFixedThreadPool(100);
- public void syn() {
- for (int i = 0; i < 1000; i++) {
- service.submit(() -> {
- integer.incrementAndGet();
- });
- }
- service.shutdown();
- System.out.println(integer.get());
- }
- public static void main(String [] args) {
- SynchroExample ex = new SynchroExample();
- ex.syn();
- }
- }
Add Comment
Please, Sign In to add comment