mirror of
https://gitee.com/jd-platform-opensource/asyncTool.git
synced 2024-12-19 03:30:30 +08:00
改下类名
This commit is contained in:
parent
f0ea3f1e1c
commit
52ace25d40
@ -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<String, String>, ICallback<String, String> {
|
||||
@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<String> workResult) {
|
||||
if (success) {
|
||||
System.out.println("callback worker0 success--" + SystemClock.now() + "----" + workResult.getResult());
|
||||
} else {
|
||||
System.err.println("callback worker0 failure--" + SystemClock.now() + "----" + workResult.getResult());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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<String, String>, ICallback<String, String> {
|
||||
@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<String> workResult) {
|
||||
if (success) {
|
||||
System.out.println("callback worker1 success--" + SystemClock.now() + "----" + workResult.getResult());
|
||||
} else {
|
||||
System.err.println("callback worker1 failure--" + SystemClock.now() + "----" + workResult.getResult());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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<String, String>, ICallback<String, String> {
|
||||
@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<String> workResult) {
|
||||
if (success) {
|
||||
System.out.println("callback worker2 success--" + SystemClock.now() + "----" + workResult.getResult());
|
||||
} else {
|
||||
System.err.println("callback worker2 failure--" + SystemClock.now() + "----" + workResult.getResult());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -9,7 +9,7 @@ import com.tianyalei.async.worker.WorkResult;
|
||||
/**
|
||||
* @author wuweifeng wrote on 2019-11-20.
|
||||
*/
|
||||
public class ParWorker implements IWorker<String, User>, ICallback<String, User> {
|
||||
public class DeWorker implements IWorker<String, User>, ICallback<String, User> {
|
||||
|
||||
@Override
|
||||
public User action(String object) {
|
@ -8,7 +8,7 @@ import com.tianyalei.async.worker.WorkResult;
|
||||
/**
|
||||
* @author wuweifeng wrote on 2019-11-20.
|
||||
*/
|
||||
public class ParWorker1 implements IWorker<WorkResult<User>, User>, ICallback<WorkResult<User>, User> {
|
||||
public class DeWorker1 implements IWorker<WorkResult<User>, User>, ICallback<WorkResult<User>, User> {
|
||||
|
||||
@Override
|
||||
public User action(WorkResult<User> result) {
|
@ -8,7 +8,7 @@ import com.tianyalei.async.worker.WorkResult;
|
||||
/**
|
||||
* @author wuweifeng wrote on 2019-11-20.
|
||||
*/
|
||||
public class ParWorker2 implements IWorker<WorkResult<User>, String>, ICallback<WorkResult<User>, String> {
|
||||
public class DeWorker2 implements IWorker<WorkResult<User>, String>, ICallback<WorkResult<User>, String> {
|
||||
|
||||
@Override
|
||||
public String action(WorkResult<User> result) {
|
@ -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<String, User> workerWrapper = new WorkerWrapper<>(w, "0", w);
|
||||
//虽然尚未执行,但是也可以先取得结果的引用,作为下一个任务的入参
|
||||
|
Loading…
Reference in New Issue
Block a user