ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ScheduledThreadPoolExecutor.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ScheduledThreadPoolExecutor.java (file contents):
Revision 1.103 by jsr166, Wed Mar 22 20:19:55 2017 UTC vs.
Revision 1.104 by jsr166, Mon Mar 27 23:53:02 2017 UTC

# Line 1178 | Line 1178 | public class ScheduledThreadPoolExecutor
1178              }
1179          }
1180  
1181        /**
1182         * Returns first element only if it is expired.
1183         * Used only by drainTo.  Call only when holding lock.
1184         */
1185        private RunnableScheduledFuture<?> peekExpired() {
1186            // assert lock.isHeldByCurrentThread();
1187            RunnableScheduledFuture<?> first = queue[0];
1188            return (first == null || first.getDelay(NANOSECONDS) > 0) ?
1189                null : first;
1190        }
1191
1181          public int drainTo(Collection<? super Runnable> c) {
1182 <            if (c == null)
1194 <                throw new NullPointerException();
1195 <            if (c == this)
1196 <                throw new IllegalArgumentException();
1197 <            final ReentrantLock lock = this.lock;
1198 <            lock.lock();
1199 <            try {
1200 <                RunnableScheduledFuture<?> first;
1201 <                int n = 0;
1202 <                while ((first = peekExpired()) != null) {
1203 <                    c.add(first);   // In this order, in case add() throws.
1204 <                    finishPoll(first);
1205 <                    ++n;
1206 <                }
1207 <                return n;
1208 <            } finally {
1209 <                lock.unlock();
1210 <            }
1182 >            return drainTo(c, Integer.MAX_VALUE);
1183          }
1184  
1185          public int drainTo(Collection<? super Runnable> c, int maxElements) {
# Line 1222 | Line 1194 | public class ScheduledThreadPoolExecutor
1194              try {
1195                  RunnableScheduledFuture<?> first;
1196                  int n = 0;
1197 <                while (n < maxElements && (first = peekExpired()) != null) {
1197 >                while (n < maxElements
1198 >                       && (first = queue[0]) != null
1199 >                       && first.getDelay(NANOSECONDS) <= 0) {
1200                      c.add(first);   // In this order, in case add() throws.
1201                      finishPoll(first);
1202                      ++n;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines