com.feilong.core.lang.thread.DefaultPartitionRunnableBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of feilong Show documentation
Show all versions of feilong Show documentation
feilong is a suite of core and expanded libraries that include utility classes, http, excel,cvs, io classes, and much much more.
/*
* Copyright (C) 2008 feilong
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.feilong.core.lang.thread;
import java.util.List;
import java.util.Map;
/**
* 默认的 {@link PartitionRunnableBuilder}.
*
* 重构:
*
*
*
* 对于以下代码:
*
*
*
*
* ThreadUtil.execute(list, 5, new PartitionRunnableBuilder{@code }(){
*
* public Runnable build(final List{@code } perBatchList,PartitionThreadEntity partitionThreadEntity,Map{@code } paramsMap){
*
* return new Runnable(){
*
* public void run(){
* map.putAll(handle(perBatchList, noList));
* }
* };
* }
* });
*
*
*
* 可以重构成:
*
*
* ThreadUtil.execute(list, 5, new DefaultPartitionRunnableBuilder{@code <>}(new Call{@code }(){
*
* public void call(List{@code } perBatchList,PartitionThreadEntity partitionThreadEntity,Map{@code } paramsMap){
* map.putAll(handle(perBatchList, noList));
* }
* }));
*
*
* 从 13 行 简写到 6 行
*
*
*
* 如果是JDK8+,还可以使用lambda重构成:
*
*
*
* ThreadUtil.execute(list, 5, new DefaultPartitionRunnableBuilder{@code <>}(new Call{@code }(){
*
* public void call(List{@code } perBatchList,PartitionThreadEntity partitionThreadEntity,Map{@code } paramsMap){
* map.putAll(handle(perBatchList, noList));
* }
* }));
*
*
* 从 13 行 简写到 6 行
*
*
*
* @author feilong
* @param
* the generic type
* @since 2.0.0
*/
public class DefaultPartitionRunnableBuilder implements PartitionRunnableBuilder{
/** The partition per handler. */
private final PartitionPerHandler partitionPerHandler;
//---------------------------------------------------------------
/**
* Instantiates a new simple partition runnable builder.
*
* @param partitionPerHandler
* the partition per handler
*/
public DefaultPartitionRunnableBuilder(PartitionPerHandler partitionPerHandler){
super();
this.partitionPerHandler = partitionPerHandler;
}
//---------------------------------------------------------------
/**
* Builds the.
*
* @param perBatchList
* the per batch list
* @param partitionThreadEntity
* the partition thread entity
* @param paramsMap
* the params map
* @return the runnable
*/
@Override
public Runnable build(final List perBatchList,final PartitionThreadEntity partitionThreadEntity,final Map paramsMap){
return () -> partitionPerHandler.handle(perBatchList, partitionThreadEntity, paramsMap);
}
}