ExecutorCompletionServiceを使用して、LinkedBlockingQueueはスレッドプールを管理してタスクを処理し、2つのタイプの結果値を返します.
8328 ワード
ExecutorCompletionServiceを使用して、LinkedBlockingQueueはスレッドプールを管理してタスクを処理し、2つのタイプの結果値を返します.
スレッドプールを日常的に使用する場合、スレッド処理結果を得る必要がある場合がよくあります.次に、特定のユーザー情報を追加し、検証した特定のインスタンスを使用して、対応する使用シーンを説明します.
1.メソッドが返す2つの結果タイプ
1.Controllerレイヤの対応する受信フロントエンドパラメータMapのセット.
2.サービス層の具体的なインタフェースと実装クラスコード.
容量4のブロックキューLinkedBlockingDequeを作成し、ExecutorCompletionServiceインスタンスnewを使用してsubmitメソッドで4つのスレッドを作成します.各スレッドは関連する資料を検証し、1つのスレッドが検証されない場合はビジネスユーザーに戻って失敗を追加します.
3.serviceは、レイヤで呼び出された検証方法を実装する.
スレッドプールを日常的に使用する場合、スレッド処理結果を得る必要がある場合がよくあります.次に、特定のユーザー情報を追加し、検証した特定のインスタンスを使用して、対応する使用シーンを説明します.
1.メソッドが返す2つの結果タイプ
import java.io.Serializable;
/**
* ,
*/
public class TwoTupleimplements Serializable {
public A first;
public B second;
public TwoTuple(A a, B b) {
this.first = a;
this.second = b;
}
public TwoTuple() {
}
@Override
public String toString() {
return "TwoTuple{" +
"first=" + first +
", second=" + second +
'}';
}
}
1.Controllerレイヤの対応する受信フロントエンドパラメータMapのセット.
/**
* showdoc
*
* @param channelCorpTemp Map
* @return {"code":200,"message":" ","data":{"..":"..."}}
* @catalog /provider
* @title
* @description
* @method POST
* @url http://ip:port/ylw/qhChannelCorp/api/addCorp
* @number 99
*/
@ResponseBody
@RequestMapping(value = "addChannel", method = RequestMethod.POST)
public ResultMessage addChannel(@RequestBody Map
2.サービス層の具体的なインタフェースと実装クラスコード.
容量4のブロックキューLinkedBlockingDequeを作成し、ExecutorCompletionServiceインスタンスnewを使用してsubmitメソッドで4つのスレッドを作成します.各スレッドは関連する資料を検証し、1つのスレッドが検証されない場合はビジネスユーザーに戻って失敗を追加します.
/**
*
*/
ResultMessage addChannel(Map
3.serviceは、レイヤで呼び出された検証方法を実装する.
// 1
private TwoTuple isChannelHasCustomer(Long corpUserId, String creditCode) {
Map params = new HashMap<>();
params.put("corpUserId", corpUserId);
params.put("creditCode", creditCode);
List count = customerTempMapper.findPage(params);
if (count != null && count.size() > 0)
return new TwoTuple<>(true, " , !");
return new TwoTuple<>(false, " ");
}
/**
* ,
*
* @return true:
*/
@ServiceImplParamAnnotation("creditCode")
public TwoTuple isChannelExist(String creditCode) {
Map params = new HashMap<>();
params.put("creditCode", creditCode);
params.put("state", ChannelTempCorpStateEnum.CHECK_SUCCESS);
List page = channelTempMapper.findPage(params);
if (page != null && page.size() > 0) {
return new TwoTuple<>(true, "success");
}
return new TwoTuple<>(false, "failed");
}
/**
*
*
* @param corpUserId id
* @return true:
*/
private TwoTuple isParentHasCustomer(Long corpUserId, String creditCode) {
Long count = customerMapper.isParentHasCustomer(corpUserId, creditCode);
if (!(count == null || count.intValue() == 0))
return new TwoTuple<>(true, " !");
return new TwoTuple<>(false, " !");
}
/**
* , ( , )
*
* @return true:
*/
private TwoTuple isOtherSubAccountHasCustomer(Long corpUserId, String creditCode) {
// id
List otherSubAccountIds = channelUserFeign.getAllOtherSubAccountId(corpUserId);
if (otherSubAccountIds == null || otherSubAccountIds.size() == 0) return new TwoTuple<>(false, " ");
Map params = new HashMap<>();
params.put("corpUserIds", otherSubAccountIds);
params.put("creditCode", creditCode);
Long count = customerMapper.isOtherSubAccountHasCustomer(params);
if (!(count == null || count.intValue() == 0))
return new TwoTuple<>(true, " !");
return new TwoTuple<>(false, " ");
}