ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/Collections/RacingCollections.java
(Generate patch)

Comparing jsr166/src/test/jtreg/util/Collections/RacingCollections.java (file contents):
Revision 1.3 by jsr166, Sun Sep 5 21:32:19 2010 UTC vs.
Revision 1.8 by jsr166, Wed Jan 4 04:46:18 2017 UTC

# Line 1 | Line 1
1   /*
2 < * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved.
2 > * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
3   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4   *
5   * This code is free software; you can redistribute it and/or modify it
# Line 38 | Line 38 | public class RacingCollections {
38       * Turn this up to some higher value like 1000 for stress testing:
39       * java -Dmillis=1000 RacingCollections
40       */
41 <    final static long defaultWorkTimeMillis = Long.getLong("millis", 10L);
41 >    static final long defaultWorkTimeMillis = Long.getLong("millis", 10L);
42  
43      /**
44       * Whether to print debug information.
45       */
46 <    final static boolean debug = Boolean.getBoolean("debug");
46 >    static final boolean debug = Boolean.getBoolean("debug");
47  
48 <    final static Integer one = 1;
49 <    final static Integer two = 2;
48 >    static final Integer one = 1;
49 >    static final Integer two = 2;
50  
51      /**
52       * A thread that mutates an object forever, alternating between
# Line 62 | Line 62 | public class RacingCollections {
62              this.start();
63          }
64  
65 <        @SuppressWarnings("unchecked") void clear(Object o) {
65 >        @SuppressWarnings("unchecked")
66 >        void clear(Object o) {
67              if (o instanceof Collection)
68                  ((Collection<?>)o).clear();
69              else
70                  ((Map<?,?>)o).clear();
71          }
72  
73 <        @SuppressWarnings("unchecked") void realRun() {
73 >        @SuppressWarnings("unchecked")
74 >        void realRun() {
75              // Mutate elLoco wildly forever, checking occasionally for "done"
76              clear(elLoco);
77              if (elLoco instanceof List) {
# Line 156 | Line 158 | public class RacingCollections {
158              quittingTime = System.nanoTime() + workTimeMillis * 1024 * 1024;
159          }
160          boolean keepGoing() {
161 <            return (i++ % 128 != 0) || (System.nanoTime() < quittingTime);
161 >            return (i++ % 128 != 0) || (System.nanoTime() - quittingTime < 0);
162          }
163      }
164  
# Line 182 | Line 184 | public class RacingCollections {
184      }
185  
186      private static List<Map<Integer, Boolean>> newConcurrentMaps() {
187 <        List<Map<Integer, Boolean>> list =
186 <            new ArrayList<Map<Integer, Boolean>>();
187 >        List<Map<Integer, Boolean>> list = new ArrayList<>();
188          list.add(new ConcurrentHashMap<Integer, Boolean>());
189          list.add(new ConcurrentSkipListMap<Integer, Boolean>());
190          return list;
# Line 194 | Line 195 | public class RacingCollections {
195          list.add(new Hashtable<Integer, Boolean>());
196          list.add(new HashMap<Integer, Boolean>());
197          list.add(new TreeMap<Integer, Boolean>());
198 <        Comparator<Integer> cmp = new Comparator<Integer>() {
198 >        Comparator<Integer> cmp = new Comparator<>() {
199              public int compare(Integer x, Integer y) {
200                  return x - y;
201              }};
# Line 203 | Line 204 | public class RacingCollections {
204      }
205  
206      private static List<Set<Integer>> newConcurrentSets() {
207 <        List<Set<Integer>> list = new ArrayList<Set<Integer>>();
207 >        List<Set<Integer>> list = new ArrayList<>();
208          list.add(new ConcurrentSkipListSet<Integer>());
209          list.add(new CopyOnWriteArraySet<Integer>());
210          return list;
# Line 218 | Line 219 | public class RacingCollections {
219      }
220  
221      private static List<List<Integer>> newConcurrentLists() {
222 <        List<List<Integer>> list = new ArrayList<List<Integer>>();
222 >        List<List<Integer>> list = new ArrayList<>();
223          list.add(new CopyOnWriteArrayList<Integer>());
224          return list;
225      }
# Line 231 | Line 232 | public class RacingCollections {
232      }
233  
234      private static List<Queue<Integer>> newConcurrentQueues() {
235 <        List<Queue<Integer>> list =
236 <            new ArrayList<Queue<Integer>>(newConcurrentDeques());
235 >        List<Queue<Integer>> list = new ArrayList<>(newConcurrentDeques());
236 >        list.add(new ArrayBlockingQueue<Integer>(10));
237          list.add(new LinkedBlockingQueue<Integer>(10));
238          list.add(new LinkedTransferQueue<Integer>());
239          list.add(new ConcurrentLinkedQueue<Integer>());
# Line 240 | Line 241 | public class RacingCollections {
241      }
242  
243      private static List<Queue<Integer>> newQueues() {
244 <        List<Queue<Integer>> list =
244 <            new ArrayList<Queue<Integer>>(newDeques());
244 >        List<Queue<Integer>> list = new ArrayList<>(newDeques());
245          list.add(new LinkedBlockingQueue<Integer>(10));
246          return list;
247      }
248  
249      private static List<Deque<Integer>> newConcurrentDeques() {
250 <        List<Deque<Integer>> list = new ArrayList<Deque<Integer>>();
250 >        List<Deque<Integer>> list = new ArrayList<>();
251          list.add(new LinkedBlockingDeque<Integer>(10));
252          list.add(new ConcurrentLinkedDeque<Integer>());
253          return list;
# Line 340 | Line 340 | public class RacingCollections {
340          try {realMain(args);} catch (Throwable t) {unexpected(t);}
341          System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
342          if (failed > 0) throw new AssertionError("Some tests failed");}
343 <    private static abstract class CheckedThread extends Thread {
343 >    private abstract static class CheckedThread extends Thread {
344          abstract void realRun() throws Throwable;
345          public void run() {
346              try { realRun(); } catch (Throwable t) { unexpected(t); }}}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines