Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class concurrent {
- volatile static int x;
- public static void test(ExecutorService pool) throws Exception{
- x = 1;
- Future<Integer> f1 = pool.submit(() -> x = x + 1);
- Future<Integer> f2 = pool.submit(() -> x = x * 5);
- f2.get();
- f1.get();
- }
- public static void main(String[] args) throws Exception {
- Set<Integer> set = new HashSet<>();
- ExecutorService pool = Executors.newFixedThreadPool(3);
- for(int i = 0 ;i < 100_000_000; i++){
- test(pool);
- set.add(x);
- }
- for(Integer e:set){
- System.out.println(e);
- }
- pool.shutdown();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement