[
https://issues.apache.org/jira/browse/JENA-1212?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15384202#comment-15384202
]
ASF GitHub Bot commented on JENA-1212:
--------------------------------------
Github user ajs6f commented on a diff in the pull request:
https://github.com/apache/jena/pull/157#discussion_r71347034
--- Diff:
jena-arq/src/main/java/org/apache/jena/atlas/data/AbortableComparator.java ---
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jena.atlas.data;
+
+import java.util.Arrays;
+import java.util.Comparator;
+
+public final class AbortableComparator<E> implements Comparator<E>
+{
+ public AbortableComparator(Comparator<? super E> comparator)
+ {
+ this.baseComparator = comparator;
+ }
+
+ /**
+ <code>AbandonSort</code> is the exception thrown from
+ <code>AbortableComparator</code> to abandon a sort.
+ */
+ public static class AbandonSort extends RuntimeException
+ {
+ private static final long serialVersionUID = 1L;
+ }
+
+ public static enum Finish {COMPLETED, ABORTED}
+
+ /**
+ The test for whether the sort has been cancelled is
+ performed every <code>cancelTestFrequency</code> comparisons.
+ This reduces the (presumed) overhead of access to a
+ volatile boolean.
+ */
+ static final int cancelTestFrequency = 10000;
+
+ /**
+ Count of the number of times this comparator has been called.
+ */
+ int count = 0;
+
+ protected volatile boolean cancelled;
+
+ final Comparator<? super E> baseComparator;
+
+ @Override public int compare(E o1, E o2)
+ {
+ count += 1;
--- End diff --
I think this might read a bit better in the next line as:
```
if (++count % cancelTestFrequency == 0)
```
> allow ORDER BY sort to be cancelled
> -----------------------------------
>
> Key: JENA-1212
> URL: https://issues.apache.org/jira/browse/JENA-1212
> Project: Apache Jena
> Issue Type: Improvement
> Components: ARQ
> Reporter: christopher james dollin
> Priority: Minor
> Fix For: Jena 3.1.1
>
>
> When a query with an ORDER BY is cancelled, the component
> Arrays.sort() that sorts the chunk(s) of the result
> bindings runs to completion before the cancel finishes.
> [See QueryIterSort and SortedDataBag.]
> For a large result set, this results in a long wait
> before the cancelled request finally finishes. This
> can be inconvenient.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)