From 52ace25d40902518a58a79d453a79f2ec4aafe7f Mon Sep 17 00:00:00 2001 From: wuweifeng10 Date: Thu, 26 Dec 2019 15:38:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E4=B8=8B=E7=B1=BB=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tianyalei/test/MyWorker.java | 42 ------------------ .../java/com/tianyalei/test/MyWorker1.java | 43 ------------------- .../java/com/tianyalei/test/MyWorker2.java | 43 ------------------- .../depend/{ParWorker.java => DeWorker.java} | 2 +- .../{ParWorker1.java => DeWorker1.java} | 2 +- .../{ParWorker2.java => DeWorker2.java} | 2 +- .../java/com/tianyalei/test/depend/Test.java | 6 +-- 7 files changed, 6 insertions(+), 134 deletions(-) delete mode 100755 src/main/java/com/tianyalei/test/MyWorker.java delete mode 100755 src/main/java/com/tianyalei/test/MyWorker1.java delete mode 100755 src/main/java/com/tianyalei/test/MyWorker2.java rename src/main/java/com/tianyalei/test/depend/{ParWorker.java => DeWorker.java} (91%) rename src/main/java/com/tianyalei/test/depend/{ParWorker1.java => DeWorker1.java} (90%) rename src/main/java/com/tianyalei/test/depend/{ParWorker2.java => DeWorker2.java} (90%) diff --git a/src/main/java/com/tianyalei/test/MyWorker.java b/src/main/java/com/tianyalei/test/MyWorker.java deleted file mode 100755 index 6a63045..0000000 --- a/src/main/java/com/tianyalei/test/MyWorker.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.tianyalei.test; - - -import com.tianyalei.async.callback.ICallback; -import com.tianyalei.async.callback.IWorker; -import com.tianyalei.async.executor.timer.SystemClock; -import com.tianyalei.async.worker.WorkResult; - -/** - * @author wuweifeng wrote on 2019-11-20. - */ -public class MyWorker implements IWorker, ICallback { - @Override - public String action(String object) { - try { - Thread.sleep(50); - } catch (InterruptedException e) { - e.printStackTrace(); - } - return "result = " + SystemClock.now() + "---param = " + object + " from 0"; - } - - @Override - public String defaultValue() { - return "worker0--default"; - } - - @Override - public void begin() { - //System.out.println(Thread.currentThread().getName() + "- start --" + System.currentTimeMillis()); - } - - @Override - public void result(boolean success, String param, WorkResult workResult) { - if (success) { - System.out.println("callback worker0 success--" + SystemClock.now() + "----" + workResult.getResult()); - } else { - System.err.println("callback worker0 failure--" + SystemClock.now() + "----" + workResult.getResult()); - } - } - -} diff --git a/src/main/java/com/tianyalei/test/MyWorker1.java b/src/main/java/com/tianyalei/test/MyWorker1.java deleted file mode 100755 index 7691a3f..0000000 --- a/src/main/java/com/tianyalei/test/MyWorker1.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.tianyalei.test; - - -import com.tianyalei.async.callback.ICallback; -import com.tianyalei.async.callback.IWorker; -import com.tianyalei.async.executor.timer.SystemClock; -import com.tianyalei.async.worker.WorkResult; - -/** - * @author wuweifeng wrote on 2019-11-20. - */ -public class MyWorker1 implements IWorker, ICallback { - @Override - public String action(String object) { - try { - Thread.sleep(50); - } catch (InterruptedException e) { - e.printStackTrace(); - } - return "result = " + SystemClock.now() + "---param = " + object + " from 1"; - } - - - @Override - public String defaultValue() { - return "worker1--default"; - } - - @Override - public void begin() { - //System.out.println(Thread.currentThread().getName() + "- start --" + System.currentTimeMillis()); - } - - @Override - public void result(boolean success, String param, WorkResult workResult) { - if (success) { - System.out.println("callback worker1 success--" + SystemClock.now() + "----" + workResult.getResult()); - } else { - System.err.println("callback worker1 failure--" + SystemClock.now() + "----" + workResult.getResult()); - } - } - -} diff --git a/src/main/java/com/tianyalei/test/MyWorker2.java b/src/main/java/com/tianyalei/test/MyWorker2.java deleted file mode 100755 index 425b2da..0000000 --- a/src/main/java/com/tianyalei/test/MyWorker2.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.tianyalei.test; - - -import com.tianyalei.async.callback.ICallback; -import com.tianyalei.async.callback.IWorker; -import com.tianyalei.async.executor.timer.SystemClock; -import com.tianyalei.async.worker.WorkResult; - -/** - * @author wuweifeng wrote on 2019-11-20. - */ -public class MyWorker2 implements IWorker, ICallback { - @Override - public String action(String object) { - try { - Thread.sleep(50); - } catch (InterruptedException e) { - e.printStackTrace(); - } - return "result = " + SystemClock.now() + "---param = " + object + " from 2"; - } - - - @Override - public String defaultValue() { - return Thread.currentThread().getName() + "--default"; - } - - @Override - public void begin() { - //System.out.println(Thread.currentThread().getName() + "- start --" + System.currentTimeMillis()); - } - - @Override - public void result(boolean success, String param, WorkResult workResult) { - if (success) { - System.out.println("callback worker2 success--" + SystemClock.now() + "----" + workResult.getResult()); - } else { - System.err.println("callback worker2 failure--" + SystemClock.now() + "----" + workResult.getResult()); - } - } - -} diff --git a/src/main/java/com/tianyalei/test/depend/ParWorker.java b/src/main/java/com/tianyalei/test/depend/DeWorker.java similarity index 91% rename from src/main/java/com/tianyalei/test/depend/ParWorker.java rename to src/main/java/com/tianyalei/test/depend/DeWorker.java index 6f2355a..a23f67d 100755 --- a/src/main/java/com/tianyalei/test/depend/ParWorker.java +++ b/src/main/java/com/tianyalei/test/depend/DeWorker.java @@ -9,7 +9,7 @@ import com.tianyalei.async.worker.WorkResult; /** * @author wuweifeng wrote on 2019-11-20. */ -public class ParWorker implements IWorker, ICallback { +public class DeWorker implements IWorker, ICallback { @Override public User action(String object) { diff --git a/src/main/java/com/tianyalei/test/depend/ParWorker1.java b/src/main/java/com/tianyalei/test/depend/DeWorker1.java similarity index 90% rename from src/main/java/com/tianyalei/test/depend/ParWorker1.java rename to src/main/java/com/tianyalei/test/depend/DeWorker1.java index c700906..e356848 100755 --- a/src/main/java/com/tianyalei/test/depend/ParWorker1.java +++ b/src/main/java/com/tianyalei/test/depend/DeWorker1.java @@ -8,7 +8,7 @@ import com.tianyalei.async.worker.WorkResult; /** * @author wuweifeng wrote on 2019-11-20. */ -public class ParWorker1 implements IWorker, User>, ICallback, User> { +public class DeWorker1 implements IWorker, User>, ICallback, User> { @Override public User action(WorkResult result) { diff --git a/src/main/java/com/tianyalei/test/depend/ParWorker2.java b/src/main/java/com/tianyalei/test/depend/DeWorker2.java similarity index 90% rename from src/main/java/com/tianyalei/test/depend/ParWorker2.java rename to src/main/java/com/tianyalei/test/depend/DeWorker2.java index 20c5dde..4e5709f 100755 --- a/src/main/java/com/tianyalei/test/depend/ParWorker2.java +++ b/src/main/java/com/tianyalei/test/depend/DeWorker2.java @@ -8,7 +8,7 @@ import com.tianyalei.async.worker.WorkResult; /** * @author wuweifeng wrote on 2019-11-20. */ -public class ParWorker2 implements IWorker, String>, ICallback, String> { +public class DeWorker2 implements IWorker, String>, ICallback, String> { @Override public String action(WorkResult result) { diff --git a/src/main/java/com/tianyalei/test/depend/Test.java b/src/main/java/com/tianyalei/test/depend/Test.java index 32cf9c9..fe0b37e 100644 --- a/src/main/java/com/tianyalei/test/depend/Test.java +++ b/src/main/java/com/tianyalei/test/depend/Test.java @@ -15,9 +15,9 @@ import java.util.concurrent.ExecutionException; public class Test { public static void main(String[] args) throws ExecutionException, InterruptedException { - ParWorker w = new ParWorker(); - ParWorker1 w1 = new ParWorker1(); - ParWorker2 w2 = new ParWorker2(); + DeWorker w = new DeWorker(); + DeWorker1 w1 = new DeWorker1(); + DeWorker2 w2 = new DeWorker2(); WorkerWrapper workerWrapper = new WorkerWrapper<>(w, "0", w); //虽然尚未执行,但是也可以先取得结果的引用,作为下一个任务的入参