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.60 by jsr166, Sat Jun 4 01:29:30 2011 UTC vs.
Revision 1.61 by jsr166, Mon Jun 6 06:28:33 2011 UTC

# Line 220 | Line 220 | public class ScheduledThreadPoolExecutor
220                  else
221                      return 1;
222              }
223 <            long d = (getDelay(TimeUnit.NANOSECONDS) -
224 <                      other.getDelay(TimeUnit.NANOSECONDS));
225 <            return (d == 0) ? 0 : ((d < 0) ? -1 : 1);
223 >            long diff = (getDelay(TimeUnit.NANOSECONDS) -
224 >                         other.getDelay(TimeUnit.NANOSECONDS));
225 >            return (diff < 0) ? -1 : (diff > 0) ? 1 : 0;
226          }
227  
228          /**
# Line 802 | Line 802 | public class ScheduledThreadPoolExecutor
802           */
803  
804          private static final int INITIAL_CAPACITY = 16;
805 <        private RunnableScheduledFuture[] queue =
806 <            new RunnableScheduledFuture[INITIAL_CAPACITY];
805 >        private RunnableScheduledFuture<?>[] queue =
806 >            new RunnableScheduledFuture<?>[INITIAL_CAPACITY];
807          private final ReentrantLock lock = new ReentrantLock();
808          private int size = 0;
809  
# Line 834 | Line 834 | public class ScheduledThreadPoolExecutor
834          /**
835           * Set f's heapIndex if it is a ScheduledFutureTask.
836           */
837 <        private void setIndex(RunnableScheduledFuture f, int idx) {
837 >        private void setIndex(RunnableScheduledFuture<?> f, int idx) {
838              if (f instanceof ScheduledFutureTask)
839                  ((ScheduledFutureTask)f).heapIndex = idx;
840          }
# Line 843 | Line 843 | public class ScheduledThreadPoolExecutor
843           * Sift element added at bottom up to its heap-ordered spot.
844           * Call only when holding lock.
845           */
846 <        private void siftUp(int k, RunnableScheduledFuture key) {
846 >        private void siftUp(int k, RunnableScheduledFuture<?> key) {
847              while (k > 0) {
848                  int parent = (k - 1) >>> 1;
849 <                RunnableScheduledFuture e = queue[parent];
849 >                RunnableScheduledFuture<?> e = queue[parent];
850                  if (key.compareTo(e) >= 0)
851                      break;
852                  queue[k] = e;
# Line 861 | Line 861 | public class ScheduledThreadPoolExecutor
861           * Sift element added at top down to its heap-ordered spot.
862           * Call only when holding lock.
863           */
864 <        private void siftDown(int k, RunnableScheduledFuture key) {
864 >        private void siftDown(int k, RunnableScheduledFuture<?> key) {
865              int half = size >>> 1;
866              while (k < half) {
867                  int child = (k << 1) + 1;
868 <                RunnableScheduledFuture c = queue[child];
868 >                RunnableScheduledFuture<?> c = queue[child];
869                  int right = child + 1;
870                  if (right < size && c.compareTo(queue[right]) > 0)
871                      c = queue[child = right];
# Line 930 | Line 930 | public class ScheduledThreadPoolExecutor
930  
931                  setIndex(queue[i], -1);
932                  int s = --size;
933 <                RunnableScheduledFuture replacement = queue[s];
933 >                RunnableScheduledFuture<?> replacement = queue[s];
934                  queue[s] = null;
935                  if (s != i) {
936                      siftDown(i, replacement);
# Line 961 | Line 961 | public class ScheduledThreadPoolExecutor
961              return Integer.MAX_VALUE;
962          }
963  
964 <        public RunnableScheduledFuture peek() {
964 >        public RunnableScheduledFuture<?> peek() {
965              final ReentrantLock lock = this.lock;
966              lock.lock();
967              try {
# Line 974 | Line 974 | public class ScheduledThreadPoolExecutor
974          public boolean offer(Runnable x) {
975              if (x == null)
976                  throw new NullPointerException();
977 <            RunnableScheduledFuture e = (RunnableScheduledFuture)x;
977 >            RunnableScheduledFuture<?> e = (RunnableScheduledFuture<?>)x;
978              final ReentrantLock lock = this.lock;
979              lock.lock();
980              try {
# Line 1016 | Line 1016 | public class ScheduledThreadPoolExecutor
1016           * holding lock.
1017           * @param f the task to remove and return
1018           */
1019 <        private RunnableScheduledFuture finishPoll(RunnableScheduledFuture f) {
1019 >        private RunnableScheduledFuture<?> finishPoll(RunnableScheduledFuture<?> f) {
1020              int s = --size;
1021 <            RunnableScheduledFuture x = queue[s];
1021 >            RunnableScheduledFuture<?> x = queue[s];
1022              queue[s] = null;
1023              if (s != 0)
1024                  siftDown(0, x);
# Line 1026 | Line 1026 | public class ScheduledThreadPoolExecutor
1026              return f;
1027          }
1028  
1029 <        public RunnableScheduledFuture poll() {
1029 >        public RunnableScheduledFuture<?> poll() {
1030              final ReentrantLock lock = this.lock;
1031              lock.lock();
1032              try {
1033 <                RunnableScheduledFuture first = queue[0];
1033 >                RunnableScheduledFuture<?> first = queue[0];
1034                  if (first == null || first.getDelay(TimeUnit.NANOSECONDS) > 0)
1035                      return null;
1036                  else
# Line 1040 | Line 1040 | public class ScheduledThreadPoolExecutor
1040              }
1041          }
1042  
1043 <        public RunnableScheduledFuture take() throws InterruptedException {
1043 >        public RunnableScheduledFuture<?> take() throws InterruptedException {
1044              final ReentrantLock lock = this.lock;
1045              lock.lockInterruptibly();
1046              try {
1047                  for (;;) {
1048 <                    RunnableScheduledFuture first = queue[0];
1048 >                    RunnableScheduledFuture<?> first = queue[0];
1049                      if (first == null)
1050                          available.await();
1051                      else {
# Line 1073 | Line 1073 | public class ScheduledThreadPoolExecutor
1073              }
1074          }
1075  
1076 <        public RunnableScheduledFuture poll(long timeout, TimeUnit unit)
1076 >        public RunnableScheduledFuture<?> poll(long timeout, TimeUnit unit)
1077              throws InterruptedException {
1078              long nanos = unit.toNanos(timeout);
1079              final ReentrantLock lock = this.lock;
1080              lock.lockInterruptibly();
1081              try {
1082                  for (;;) {
1083 <                    RunnableScheduledFuture first = queue[0];
1083 >                    RunnableScheduledFuture<?> first = queue[0];
1084                      if (first == null) {
1085                          if (nanos <= 0)
1086                              return null;
# Line 1119 | Line 1119 | public class ScheduledThreadPoolExecutor
1119              lock.lock();
1120              try {
1121                  for (int i = 0; i < size; i++) {
1122 <                    RunnableScheduledFuture t = queue[i];
1122 >                    RunnableScheduledFuture<?> t = queue[i];
1123                      if (t != null) {
1124                          queue[i] = null;
1125                          setIndex(t, -1);
# Line 1135 | Line 1135 | public class ScheduledThreadPoolExecutor
1135           * Return and remove first element only if it is expired.
1136           * Used only by drainTo.  Call only when holding lock.
1137           */
1138 <        private RunnableScheduledFuture pollExpired() {
1139 <            RunnableScheduledFuture first = queue[0];
1138 >        private RunnableScheduledFuture<?> pollExpired() {
1139 >            RunnableScheduledFuture<?> first = queue[0];
1140              if (first == null || first.getDelay(TimeUnit.NANOSECONDS) > 0)
1141                  return null;
1142              return finishPoll(first);
# Line 1150 | Line 1150 | public class ScheduledThreadPoolExecutor
1150              final ReentrantLock lock = this.lock;
1151              lock.lock();
1152              try {
1153 <                RunnableScheduledFuture first;
1153 >                RunnableScheduledFuture<?> first;
1154                  int n = 0;
1155                  while ((first = pollExpired()) != null) {
1156                      c.add(first);
# Line 1172 | Line 1172 | public class ScheduledThreadPoolExecutor
1172              final ReentrantLock lock = this.lock;
1173              lock.lock();
1174              try {
1175 <                RunnableScheduledFuture first;
1175 >                RunnableScheduledFuture<?> first;
1176                  int n = 0;
1177                  while (n < maxElements && (first = pollExpired()) != null) {
1178                      c.add(first);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines