-
Notifications
You must be signed in to change notification settings - Fork 766
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(priority executor): add ThreadPoolBuilder #283
- Loading branch information
Showing
8 changed files
with
260 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ | |
package org.dromara.dynamictp.core.executor.priority; | ||
|
||
/** | ||
* Priority related | ||
* | ||
* @author <a href = "mailto:[email protected]">KamTo Hung</a> | ||
*/ | ||
public interface Priority { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ | |
import java.util.concurrent.Callable; | ||
|
||
/** | ||
* PriorityCallable related | ||
* | ||
* @author <a href = "mailto:[email protected]">KamTo Hung</a> | ||
*/ | ||
public class PriorityCallable<V> implements Priority, Callable<V> { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,9 @@ | |
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.dromara.dynamictp.core.executor.DtpExecutor; | ||
import org.dromara.dynamictp.core.support.task.runnable.DtpRunnable; | ||
|
||
import java.util.Comparator; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
|
@@ -29,6 +31,8 @@ | |
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* PriorityDtpExecutor related, extending DtpExecutor, implements priority feature | ||
* | ||
* @author <a href = "mailto:[email protected]">KamTo Hung</a> | ||
*/ | ||
@Slf4j | ||
|
@@ -155,4 +159,24 @@ public <T> Future<T> submit(Callable<T> task, int priority) { | |
return super.submit(PriorityCallable.of(task, priority)); | ||
} | ||
|
||
|
||
/** | ||
* Priority Comparator | ||
* | ||
* @return Comparator | ||
*/ | ||
public static Comparator<Runnable> getRunnableComparator() { | ||
return (o1, o2) -> { | ||
if (!(o1 instanceof DtpRunnable) || !(o2 instanceof DtpRunnable)) { | ||
return 0; | ||
} | ||
Runnable po1 = ((DtpRunnable) o1).getOriginRunnable(); | ||
Runnable po2 = ((DtpRunnable) o2).getOriginRunnable(); | ||
if (po1 instanceof Priority && po2 instanceof Priority) { | ||
return Integer.compare(((Priority) po1).getPriority(), ((Priority) po2).getPriority()); | ||
} | ||
return 0; | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ | |
import java.util.concurrent.FutureTask; | ||
|
||
/** | ||
* PriorityFutureTask related | ||
* | ||
* @author <a href = "mailto:[email protected]">KamTo Hung</a> | ||
*/ | ||
public class PriorityFutureTask<V> extends FutureTask<V> implements Priority { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
import lombok.Getter; | ||
|
||
/** | ||
* PriorityRunnable related | ||
* | ||
* @author <a href = "mailto:[email protected]">KamTo Hung</a> | ||
*/ | ||
public class PriorityRunnable implements Priority, Runnable { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.