WANG 5 年之前
父节点
当前提交
c10f375e66

+ 6 - 6
src/main/java/cn/com/qmth/examcloud/commons/helpers/concurrency/simple/ConcurrentTask.java

@@ -16,11 +16,11 @@ import cn.com.qmth.examcloud.commons.util.Util;
  * @date 2019年6月19日
  * @Copyright (c) 2018-2020 WANGWEI [QQ:522080330] All Rights Reserved.
  */
-public class ConcurrentTask {
+public class ConcurrentTask<T> {
 
 	private static final ExamCloudLog LOG = ExamCloudLogFactory.getLog(ConcurrentTask.class);
 
-	private BlockingQueue<Object> queue = new LinkedBlockingQueue<Object>(10000);
+	private BlockingQueue<T> queue = new LinkedBlockingQueue<T>(10000);
 
 	private BlockingQueue<Integer> workerMessages = new LinkedBlockingQueue<Integer>(10000);
 
@@ -41,7 +41,7 @@ public class ConcurrentTask {
 	/**
 	 * 处理者
 	 */
-	private Worker worker;
+	private Worker<T> worker;
 
 	/**
 	 * 巡检周期
@@ -55,7 +55,7 @@ public class ConcurrentTask {
 	 * @param e
 	 * @return
 	 */
-	public boolean offerElement(Object e) {
+	public boolean offerElement(T e) {
 		boolean offer = queue.offer(e);
 		if (LOG.isDebugEnabled()) {
 			LOG.debug("offerElement. result=" + offer + ";element=" + e.toString());
@@ -125,7 +125,7 @@ public class ConcurrentTask {
 			@Override
 			public void run() {
 				while (true) {
-					Object el = queue.poll();
+					T el = queue.poll();
 					if (null == el) {
 						nullTimes++;
 						if (10 <= nullTimes) {
@@ -177,7 +177,7 @@ public class ConcurrentTask {
 		this.minThreadSize = minThreadSize;
 	}
 
-	public void setWorker(Worker worker) {
+	public void setWorker(Worker<T> worker) {
 		this.worker = worker;
 	}
 

+ 2 - 2
src/main/java/cn/com/qmth/examcloud/commons/helpers/concurrency/simple/Worker.java

@@ -1,7 +1,7 @@
 package cn.com.qmth.examcloud.commons.helpers.concurrency.simple;
 
-public interface Worker {
+public interface Worker<T> {
 
-	void process(final WorkerController controller, Object element);
+	void process(final WorkerController controller, T element);
 
 }