Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized code #389

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,42 @@

/**
* Priority related
* <p>The {@link #getPriority()} is optional and represents a priority value as defined in the
* {@link Priority} interface. Lower values have higher priority. The default value is
* {@code Priority.LOWEST_PRECEDENCE}, indicating the lowest priority (losing to any
* other specified priority value).
*
* @author <a href = "mailto:[email protected]">KamTo Hung</a>
* @since 1.1.7
*/
public interface Priority {

/**
* Useful constant for the highest precedence value.
*
* @see java.lang.Integer#MIN_VALUE
*/
int HIGHEST_PRECEDENCE = Integer.MIN_VALUE;

/**
* Useful constant for the lowest precedence value.
*
* @see java.lang.Integer#MAX_VALUE
*/
int LOWEST_PRECEDENCE = Integer.MAX_VALUE;

/**
* Get the priority value of this object.
* <p>Higher values are interpreted as lower priority. As a consequence,
* the object with the lowest value has the highest priority (somewhat
* analogous to Servlet {@code load-on-startup} values).
* <p>Same priority values will result in arbitrary sort positions for the
* affected objects.
*
* @return the priority value
* @see #HIGHEST_PRECEDENCE
* @see #LOWEST_PRECEDENCE
*/
int getPriority();

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* PriorityCallable related
*
* @author <a href = "mailto:[email protected]">KamTo Hung</a>
* @since 1.1.7
*/
public class PriorityCallable<V> implements Priority, Callable<V> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@
* PriorityDtpExecutor related, extending DtpExecutor, implements priority feature
*
* @author <a href = "mailto:[email protected]">KamTo Hung</a>
* @since 1.1.7
*/
@Slf4j
public class PriorityDtpExecutor extends DtpExecutor {

/**
* The default priority.
*/
private static final int DEFAULT_PRIORITY = 0;

public PriorityDtpExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
Expand Down Expand Up @@ -133,7 +129,7 @@ public void execute(Runnable command, int priority) {

@Override
public Future<?> submit(Runnable task) {
return super.submit(PriorityRunnable.of(task, DEFAULT_PRIORITY));
return super.submit(PriorityRunnable.of(task, Priority.LOWEST_PRECEDENCE));
}

public Future<?> submit(Runnable task, int priority) {
Expand All @@ -142,7 +138,7 @@ public Future<?> submit(Runnable task, int priority) {

@Override
public <T> Future<T> submit(Runnable task, T result) {
return super.submit(PriorityRunnable.of(task, DEFAULT_PRIORITY), result);
return super.submit(PriorityRunnable.of(task, Priority.LOWEST_PRECEDENCE), result);
}

public <T> Future<T> submit(Runnable task, T result, int priority) {
Expand All @@ -151,7 +147,7 @@ public <T> Future<T> submit(Runnable task, T result, int priority) {

@Override
public <T> Future<T> submit(Callable<T> task) {
return super.submit(PriorityCallable.of(task, DEFAULT_PRIORITY));
return super.submit(PriorityCallable.of(task, Priority.LOWEST_PRECEDENCE));
}

public <T> Future<T> submit(Callable<T> task, int priority) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* PriorityFutureTask related
*
* @author <a href = "mailto:[email protected]">KamTo Hung</a>
* @since 1.1.7
*/
public class PriorityFutureTask<V> extends FutureTask<V> implements Priority {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* PriorityRunnable related
*
* @author <a href = "mailto:[email protected]">KamTo Hung</a>
* @since 1.1.7
*/
public class PriorityRunnable implements Priority, Runnable {

Expand Down