Guest User

Untitled

a guest
Jul 20th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. public class SynchroExample {
  2.  
  3. public final AtomicInteger integer = new AtomicInteger(0);
  4.  
  5. private ExecutorService service = Executors.newFixedThreadPool(100);
  6.  
  7. public void syn() {
  8. for (int i = 0; i < 1000; i++) {
  9. service.submit(() -> {
  10. integer.incrementAndGet();
  11. });
  12. }
  13. service.shutdown();
  14. System.out.println(integer.get());
  15. }
  16.  
  17. public static void main(String [] args) {
  18. SynchroExample ex = new SynchroExample();
  19. ex.syn();
  20. }
  21. }
Add Comment
Please, Sign In to add comment