当前位置: 首页 > news >正文

芜湖门户网站建设多少钱如何提高权重

芜湖门户网站建设多少钱,如何提高权重,官网创建模版,wordpress红色主题在Java中进行异步计算是比较难以理解的。一般来说#xff0c;我们希望将任何计算都视为一系列步骤#xff0c;但是在异步的情况下#xff0c;这些步骤通常以回调函数的形式存在#xff0c;要么散布在代码中#xff0c;要么互相嵌套的很深。而我们需要处理可能发生在某个步…在Java中进行异步计算是比较难以理解的。一般来说我们希望将任何计算都视为一系列步骤但是在异步的情况下这些步骤通常以回调函数的形式存在要么散布在代码中要么互相嵌套的很深。而我们需要处理可能发生在某个步骤中的错误时情况就变得更加复杂而CompletableFuture就是来解决这些“困扰”的。 一、什么是CompletableFuture CompletableFuture是Java 8中引入的一个类用于异步编程和并发操作它大约提供了50个不同的方法用于组合、合并和执行异步计算步骤以及处理错误。 下面是它的继承关系 从图中可以看出CompletableFuture类实现了Future和CompletionStage接口这两个接口分别代表了异步任务的结果和完成状态以及异步任务之间的依赖关系。 FutureJava 5新加的一个接口它提供一种异步并行计算的功能如果主线程需要执行一个很耗时的计算任务那么我们可以通过Future把这个任务放进异步线程中执行并且可以通过Future获取计算结果。 CompletionStage 提供了非常强大的Future的扩展功能可以帮助我们简化异步编程的复杂性并且提供了函数式编程的能力可以通过回调的方式处理计算结果也提供了转换和组合CompletableFuture的方法。 他可能代表一个明确完成的Future也可能代表一个完成阶段CompletionStage它支持在计算完成以后出发一些函数或执行某些动作。 二、CompletableFuture的底层实现 底层实现主要涉及到了几个重要的技术手段如Completion链式异步处理、事件驱动、ForkJoinPool线程池、通过CompletionException捕获异常、CAS操作等。 链式结构CompletableFuture内部采用了一种链式结构来处理异步计算的结果每个CompletableFuture都有一个与之关联的Completion链它可以包含多个Completion阶段每个阶段都代表一个异步操作并且可以指定它所依赖的前一个计算结果。【在CompletableFuture类中定义了一个内部类Completion它表示Completion链的一个阶段其中包含了前一个阶段的计算结果、下一个阶段的计算操作以及执行计算操作的线程池等信息。】 事件驱动CompletableFuture还使用了一种事件驱动的机制来处理异步计算的完成事件。在一个ComletableFuture对象上注册的Completion阶段完成后它会出发一个完成事件然后CompletableFuture对象会执行与之关联的下一个Completion阶段。 ForkJoinPoolCompletableFuture的异步计算是通过线程池来实现的。它在内部使用了一个ForkJoinPool线程池来执行异步任务。ForkJoinPool是一种特殊的线程池使用了工作窃取算法来提高多线程的执行效率、可以根据需要动态地创建和回收线程、线程之间还可以共享任务从而更好地利用计算资源。 捕获异常CompletableFuture会通过内部的CompletionException来捕获计算过程中出现的异常。 CAS操作CompletableFuture在状态转换和任务完成通知的过程中使用CAS操作来保证线程安全。 三、CompletbaleFuture的使用 3.0 六个函数式接口 CompletableFuture方法的入参大部分是函数式接口在学习之前先了解一下还是必要的。 3.1 四个静态方法 CompletableFuture提供了四个静态方法来创建一个异步操作 public static CompletableFutureVoid runAsync(Runnable runnable) public static CompletableFutureVoid runAsync(Runnable runnable, Executor executor) public static U CompletableFutureU supplyAsync(SupplierU supplier) public static U CompletableFutureU supplyAsync(SupplierU supplier, Executor executor) runAsync()方法用Runnable函数时接口类型作为参数无返回值supplyAsync()方法以Supplier函数式接口作为参数有返回值【用get()方法以阻塞的形式获取返回计算结果】。 Executor参数可传可不传若不传就用默认的ForkJoinPool线程池反之用传入的线程池。 示例 public class FourStaticDemo {public static void main(String[] args) throws ExecutionException, InterruptedException {//1.无返回值且默认线程池CompletableFutureVoid future CompletableFuture.runAsync(() - {System.out.println(无返回值);}); ​//2.有返回值且自定义线程池CompletableFutureString future1 CompletableFuture.supplyAsync(() - {System.out.println(有返回值);return hello world;}, Executors.newFixedThreadPool(1));//获取返回值阻塞String s future1.get();System.out.println(s s);} } 有没有不阻塞获取结果的方法当然有可以用 public static U CompletableFutureU completedFuture(U value) 如果我们已经知道计算结果我们可以用静态的completedFuture()方法该方法接收一个表示计算结果的参数因此它的get()方法不会阻塞而是立即返回这个结果。 3.2 结果传递 3.2.1 thenApply() 它接收一个Function示例用它来处理结果。 public U CompletableFutureU thenApply(Function? super T,? extends U fn) public U CompletableFutureU thenApplyAsync(Function? super T,? extends U fn) public U CompletableFutureU thenApplyAsync(Function? super T,? extends U fn, Executor executor) thenApply()将前面任务的执行结果交给后面的Function。 thenApplyAsync()异步执行。 示例thenApply入参传入Function函数式接口重写apply方法。 public class ThenApplyDemo { ​public static void main(String[] args) throws ExecutionException, InterruptedException {//返回一个helloCompletableFutureString future CompletableFuture.supplyAsync(() - hello);CompletableFutureString future1 future.thenApply(new FunctionString, String() {Overridepublic String apply(String s) {return s world;}});String s future1.get();System.out.println(s);//hello world} } ps上面是完整的写法后面就用Lambda表达式的简化写法了哈。 3.2.2 thenAccept() 如果我们不需要在Future链中返回一个值我们可以使用Consumer功能接口的实例。 public CompletableFutureVoid thenAccept(Consumer? super T action) public CompletableFutureVoid thenAcceptAsync(Consumer? super T action) public CompletableFutureVoid thenAcceptAsync(Consumer? super T action,Executor executor) thenAccept()将前面任务的执行结果交给后面的Consumer。 thenAcceptAsync()异步执行。 示例 public class ThenAcceptDemo {public static void main(String[] args) {CompletableFutureString future CompletableFuture.supplyAsync(() - hello);CompletableFutureVoid future1 future.thenAccept(s - System.out.println(s world));//hello world} } 3.2.3 thenRun() 如果我们既不需要计算结果的值也不想在链的最后返回任何值那么我们可以使用thenRun()方法。 public CompletableFutureVoid thenRun(Runnable action) public CompletableFutureVoid thenRunAsync(Runnable action) public CompletableFutureVoid thenRunAsync(Runnable action,Executor executor) thenRun()将前面任务的执行结果交给后面的Runnable。 thenRunAsync()异步执行。 示例 public class ThenRunDemo {public static void main(String[] args) {CompletableFutureString future CompletableFuture.supplyAsync(() - hello);CompletableFutureVoid future1 future.thenRun(() - System.out.println(hello world));//hello world} } 3.2.4 thenApply()thenAccpet() public class ApplyAcceptDemo {public static void main(String[] args) {ExecutorService threadPool Executors.newFixedThreadPool(3);CompletableFuture.supplyAsync(() - {return 1;}, threadPool).thenApply(f - {return f 2;}).thenApply(f - {return f 2;}).thenAccept(r - {System.out.println(r);//5});} } 3.3 合并结果 CompletableFuture API最好的部分是能够将CompletableFuture实例组合成计算步骤链条。 3.3.1 thenCompose() 此方法接收一个返回CompletableFuture实例的函数。该函数的参数是上一步计算的结果。这使得我们可以在下一个CompletableFuture的lambda表达式中使用这个值 public U CompletableFutureU thenCompose(Function? super T, ? extends CompletionStageU fn) public U CompletableFutureU thenComposeAsync(Function? super T, ? extends CompletionStageU fn) public U CompletableFutureU thenComposeAsync(Function? super T, ? extends CompletionStageU fn,Executor executor) thenCompose()用来连接两个有依赖关系的任务结果由第二个任务返回。 thenComposeAsync()异步执行。 示例 public class ThenCompose {public static void main(String[] args) throws ExecutionException, InterruptedException {CompletableFutureString future CompletableFuture.supplyAsync(() - hello).thenCompose(s - CompletableFuture.supplyAsync(() - s world));String s future.get();System.out.println(s);//hello world} } 3.3.2 thenCombine() 如果我们想执行两个独立的Futures并对它们的结果进行处理我们可以使用thenCombine方法该方法接收一个Future和一个带有两个参数的函数来处理两个结果。 public U,V CompletableFutureV thenCombine(CompletionStage? extends U other, BiFunction? super T,? super U,? extends V fn) public U,V CompletableFutureV thenCombineAsync(CompletionStage? extends U other,BiFunction? super T,? super U,? extends V fn) public U,V CompletableFutureV thenCombineAsync(CompletionStage? extends U other,BiFunction? super T,? super U,? extends V fn, Executor executor) thenCombine()合并两个任务。 thenCombineAsync()异步执行。 示例 public class ThenCombineDemo {public static void main(String[] args) throws Exception {CompletableFutureString future CompletableFuture.supplyAsync(() - hello).thenCombine(CompletableFuture.supplyAsync(() - world), (s1, s2) - s1 s2);String s future.get();System.out.println(s);//hello world} } 3.3.3 thenAcceptBoth() 一个更简单的情况是当我们相对两个Future的结果进行操作但不需要将任何结果传递给Future链中时可以使用thenAcceptBoth()方法。 public U CompletableFutureVoid thenAcceptBoth(CompletionStage? extends U other,BiConsumer? super T, ? super U action) public U CompletableFutureVoid thenAcceptBothAsync(CompletionStage? extends U other,BiConsumer? super T, ? super U action) public U CompletableFutureVoid thenAcceptBothAsync(CompletionStage? extends U other,BiConsumer? super T, ? super U action, Executor executor) thenAcceptBoth()两个任务执行完成后将结果交给thenAcceptBoth处理。 thenAcceptBothAsync()异步执行。 示例 public class ThenAccpetBothDemo {public static void main(String[] args) {CompletableFuture.supplyAsync(()-hello).thenAcceptBoth(CompletableFuture.supplyAsync(()- world),(s1,s2)- System.out.println(s1s2));//hello world} } 3.4 异常处理 在一系列异步计算步骤中处理错误抛出/捕获使我们惯用的方式。 3.4.1 whenComplete() CompletableFuture类允许我们用whenComplete()方法来处理异常参数是函数式接口Biconsumer可以接收两个参数计算的结果如果成功完成和抛出的异常没有正常完成 public CompletableFutureT whenComplete(BiConsumer? super T, ? super Throwable action) public CompletableFutureT whenCompleteAsync(BiConsumer? super T, ? super Throwable action) public CompletableFutureT whenCompleteAsync(BiConsumer? super T, ? super Throwable action, Executor executor) whenComplete()当任务完成时可以使用结果和此阶段的异常执行操作。 whenCompleteAsync()异步执行。 示例 public class WhenCompleteDemo {public static void main(String[] args) {CompletableFutureInteger future CompletableFuture//除0异常.supplyAsync(() - { int i 1 / 0; return i;}).whenComplete((v, e) - {if (e ! null) {//出现异常处理。。System.out.println(出现异常啦异常e.getMessage());}//没有异常System.out.println(v);});} } 运行结果 3.4.2 exceptionally() exceptionally()方法是纯处理异常的操作参数为Function函数式接口接收的是一个Throwable类型的异常。 public CompletableFutureT exceptionally(FunctionThrowable, ? extends T fn) exceptionally()此方法前的链中如果出现异常会走该方法一般跟whenComplete配合使用捕获范围包含此方法前的所有链中的异常。 ps出现异常才会走而whenComplete()出没出现都会走。 示例 public class ExceptionallyDemo {public static void main(String[] args) {CompletableFutureInteger future CompletableFuture.supplyAsync(() - {int i 1 / 1; return i;}).exceptionally(e - {System.out.println(出现异常啦 e.getCause());return null;});} } 3.4.3 handle() handle()和whenComplete()类似也是接收两个参数计算的结果如果成功完成和抛出的异常没有正常完成不同的是handle()用的是BiFunction函数式接口。 public U CompletableFutureU handle(BiFunction? super T, Throwable, ? extends U fn) public U CompletableFutureU handleAsync(BiFunction? super T, Throwable, ? extends U fn) public U CompletableFutureU handleAsync(BiFunction? super T, Throwable, ? extends U fn, Executor executor) handle()相当于whenCompleteexceptionally。 handleAsync()异步执行。 示例 public class HandleDemo {public static void main(String[] args) {CompletableFutureInteger future CompletableFuture//除0异常.supplyAsync(() - { int i 1 / 0; return i;}).handle((v, e) - {if (e ! null) {//出现异常处理。。System.out.println(出现异常啦异常e.getMessage());}//没有异常return v1;});} } ps乍一看whenComplete()和handle()没有什么区别其实不然。whenComplete()是以BiConsumer函数式接口作为参数而BiConsumer没有返回值就不能对上一任务的结果进行“替换”。handle()以BiFunction作为参数它有返回值这就意味着可以对上一任务的结果进行“替换”。说正式点就是whenComplete()不能消费异常而handle()可以消费异常可以把异常的结果替换成“正常的结果”。 3.4.4 whenComplete()exceptionally()handle() 示例 public class WhenExceptionHandleDemo {public static void main(String[] args) {CompletableFutureInteger future CompletableFuture.supplyAsync(() - {return 1;}).handle((f, e) - {System.out.println(----handle()----);if(enull){return f 2;}return null;}).whenComplete((v, e) - {if (e null) {//没有异常System.out.println(result v);throw new RuntimeException(抛个异常---);}}).exceptionally(e - {System.out.println(e.getCause());return null;});} } 运行结果 3.5 根据计算速度选用 这也比较好理解就是看两个任务的处理速度谁快就触发下一步的动作。 3.5.1 applyToEither() 两个任务谁快用谁的计算结果有返回值。 public U CompletableFutureU applyToEither(CompletionStage? extends T other, Function? super T, U fn) public U CompletableFutureU applyToEitherAsync(CompletionStage? extends T other, Function? super T, U fn) public U CompletableFutureU applyToEitherAsync(CompletionStage? extends T other,Function? super T, U fn,Executor executor) applyToEither()两个任务比较谁先获得计算结果就用谁。 applyToEitherAsync()异步执行。 示例 public class ApplyToEitherDemo {public static void main(String[] args) throws Exception {CompletableFutureString future1 CompletableFuture.supplyAsync(() - {return A;});CompletableFutureString future2 CompletableFuture.supplyAsync(() - {try {//睡0.1秒Thread.sleep(100);} catch (InterruptedException e) {throw new RuntimeException(e);}return B;});CompletableFutureString result future1.applyToEither(future2, v - {return v 比较快;});String res result.get();System.out.println(res);//A比较快} } 3.5.2 accpetEither 和applyToEither差不多区别在于没有返回值。 public CompletableFutureVoid acceptEither(CompletionStage? extends T other, Consumer? super T action) public CompletableFutureVoid acceptEitherAsync(CompletionStage? extends T other, Consumer? super T action) public CompletableFutureVoid acceptEitherAsync(CompletionStage? extends T other, Consumer? super T action,Executor executor) acceptEither()两个任务比较谁先获得计算结果就用谁。 acceptEitherAsync()异步执行。 示例 public class AcceptToEitherDemo {public static void main(String[] args) throws Exception {CompletableFutureString future1 CompletableFuture.supplyAsync(() - {return A;});CompletableFutureString future2 CompletableFuture.supplyAsync(() - {try {//睡0.1秒Thread.sleep(100);} catch (InterruptedException e) {throw new RuntimeException(e);}return B;});CompletableFutureVoid result future1.acceptEither(future2, v - {System.out.println(v比较快);//A比较快});} } 3.5.3 runAfterEither() 两个任务任一先执行完就进行下一步操作不用计算结果也无返回值。 public CompletableFutureVoid runAfterEither(CompletionStage? other,Runnable action) public CompletableFutureVoid runAfterEitherAsync(CompletionStage? other,Runnable action) public CompletableFutureVoid runAfterEitherAsync(CompletionStage? other,Runnable action,Executor executor) runAfterEither()两个任务有任何一个执行完成就进入下一步操作无返回值。 runAfterEitherAsync()异步执行。 示例 public class RunAfterEitherDemo {public static void main(String[] args) {CompletableFutureString future1 CompletableFuture.supplyAsync(() - {return A;});CompletableFutureString future2 CompletableFuture.supplyAsync(() - {try {//睡0.1秒Thread.sleep(100);} catch (InterruptedException e) {throw new RuntimeException(e);}return B;});CompletableFutureVoid result future1.runAfterEither(future2, () - {System.out.println(有任务完成啦);});//有任务完成啦} } 3.6 等待一组任务完成 当需要同时执行多个异步操作并等待所有或者任何一个操作完成后再进行下一步操作时就可以考虑使用以下两个方法一般配合join()使用。 3.6.1 allOf() 合并多个任务为一个等待全部完成无返回值。 public static CompletableFutureVoid allOf(CompletableFuture?... cfs) allOf()多个任务全部执行完返回。 示例 public class AllOfDemo {public static void main(String[] args) {CompletableFutureInteger future1 CompletableFuture.supplyAsync(() - {try {Thread.sleep(1000);} catch (InterruptedException e) {throw new RuntimeException(e);}System.out.println(future1 执行);return 1;});CompletableFutureInteger future2 CompletableFuture.supplyAsync(() - {try {Thread.sleep(2000);} catch (InterruptedException e) {throw new RuntimeException(e);}System.out.println(future2 执行);return 2;});CompletableFutureInteger future3 CompletableFuture.supplyAsync(() - {try {Thread.sleep(3000);} catch (InterruptedException e) {throw new RuntimeException(e);}System.out.println(future3 执行);return 3;});//阻塞三个任务CompletableFuture.allOf(future1, future2, future3).join();System.out.println(future1、future2、future3全部执行完毕);} } 输出结果 3.6.2 anyOf() 合并多个任务为一个任意一个执行完成就进行下一步操作有返回值。 public static CompletableFutureObject anyOf(CompletableFuture?... cfs) anyOf()多个任务任一执行完就返回。 示例 public class AllOfDemo {public static void main(String[] args) throws ExecutionException, InterruptedException {CompletableFutureString future1 CompletableFuture.supplyAsync(() - {try {Thread.sleep(100);} catch (InterruptedException e) {throw new RuntimeException(e);}System.out.println(future1 执行);return A;});CompletableFutureString future2 CompletableFuture.supplyAsync(() - {try {Thread.sleep(200);} catch (InterruptedException e) {throw new RuntimeException(e);}System.out.println(future2 执行);return B;});CompletableFutureString future3 CompletableFuture.supplyAsync(() - {try {Thread.sleep(300);} catch (InterruptedException e) {throw new RuntimeException(e);}System.out.println(future3 执行);return C;});//阻塞三个任务CompletableFutureObject obj CompletableFuture.anyOf(future1, future2, future3);Object o obj.get();System.out.println(o执行完了);} } 输出结果 3.7 其它api和Java9新增的api 3.7.1 Java 8 public T join() public T getNow(T valueIfAbsent) public boolean isCompletedExceptionally() public int getNumberOfDependents() 解释 join()阻塞获取结果不需要抛出异常。 getNow()计算完成就返回正常值否则返回备胎值传入的参数立即获取不阻塞。 isCompletedExceptionally()判断任务是否异常结束。 getNumberOfDependents()返回依赖当前任务的任务数量。 3.7.2 Java 9 CompletableFutureU newIncompleteFuture() CompletableFutureT copy() CompletionStageT minimalCompletionStage() CompletableFutureT orTimeout(long timeout, TimeUnit unit) CompletableFutureT completeOnTimeout(T value, long timeout, TimeUnit unit) 解释 newIncompleteFuture()也被称为“虚拟构造函数”用于获取相同类型的新的Completable实例。 copy()返回一个新的CompletableFuture。 minimalCompletionStage()返回一个新的CompletionStage。 orTimeout()若在指定的超时时间之前未完成则会以异常TimeoutException结束。 completeOnTimeout()若在指定的超时时间之前未完成则以给定的value为任务结果。 四、Future接口 简单介绍一下Future接口Future是Java 5新加的一个接口他在处理异步调用和并发处理时非常有用。 4.1 什么是Future 简单来说Future类代表了一个异步计算的未来结果。这个结果将在处理完成后最终出现在Future中。 如果主线程需要执行一个很耗时的计算任务那么Future将是一个不错的选择我们可以通过Future把这个任务放入异步线程中去执行主线程就可以去处理其它任务或提前结束。 4.2 Future的相关Api boolean cancel(boolean mayInterruptIfRunning); boolean isCancelled(); boolean isDone(); V get() V get(long timeout, TimeUnit unit) 解释 cancel()取消任务若一个任务未完成则以CancellationException异常结束。其相关未完成的子任务也会以此异常结束。 isCancelled()判断任务是否已取消若任务在正常执行前取消则返回ture反之返回false。 isDone()判断任务是否完成。三种完成情况正常执行完成、异常完成和已取消。 get()以阻塞的方式获取计算结果需要处理异常捕获或者直接抛。 get(long timeout,TimeUnit unit)若超过设置的时间还未获取到结果就直接抛异常。 4.3 FutureTask FutureTask也是Future的一个实现类下面我们来看一个例子 public class FutureTaskDemo {public static void main(String[] args) throws Exception {FutureTaskString task new FutureTask(() - {return hello world;});new Thread(task).start();//阻塞获取结果System.out.println(task.get());//hello world} } 4.4 与CompletableFuture对比 阻塞等待 Future接口的get()方法在获取计算结果时会阻塞等待可能导致线程资源浪费和性能问题。 CompletableFuture提供了一系列非阻塞的方法如thenApply()、thenCompose()等。 无法手动完成或取消 Future接口的实现类无法手动标记任务的完成或取消状态只能依赖于任务本身的执行状态。 CompletableFuture提供了如complete()、completeExceptionally()、cancel()等以便手动设置异步任务的结果、异常或取消状态。 缺乏异常梳理机制 Future接口的get()方法在异步任务会抛出异常但在任务完成前无法捕获和处理异常。 CompletableFuture提供了exceptionally()和handle()方法可以方便地对异步任务的异常情况进行处理和转换。 缺少组合能力 Future接口无法直接组合多个异步任务不能方便的实现串行、并行等操作。 CompletableFuture提供了一系列方法如thenApply()、thenCompose()和thenCombine()等可以方便地实现异步任务的组合。 缺少回调机制 Future接口无法在异步任务完成时自动触发回调函数执行。 CompletableFuture提供了如thenApply()、thenAccpept()、thenRun()等可以在任务完成时自动执行回调函数。 总之一句话Future能干的CompletableFuture都能干Future不能干的CompletableFuture也能干 五、ForkJoinPool 5.1 Fork/Join框架 Java 7引入了Fork/Join框架它提供了一些工具通过尽可能地提高cpu的利用率来加速并行处理它通过分而治之的方法来实现这一点的。 实际上这意味着该框架首先进行“fork”操作递归地将任务分解为较小的独立子任务知道它们足够简单可以异步运行。 之后开始“join”部分。所有的子任务的结果被递归地合并为一个单一的结果。对于返回void的任务程序会简单地等待每个子任务运行完毕。 为了提供有效的并行执行Fork/Join框架使用了一个线程池——ForkJoinPool。 5.2 ForkJoinPool ForkJoinPool是该框架的核心。它是ExecutorService的一个实现负责管理工作线程并提供工具以获取有关线程池的状态和性能信息。 工作线程一次只能执行一个任务但ForkJoinPool并不为每个子任务创建一个单独的线程。相反池中的每个线程都有自己的双端队列deque用于存储任务。 5.2.1 工作窃取算法 简单来说空闲的线程会尝试从繁忙线程的deque中“窃取”任务。 默认情况下工作线程从自己的deque头部获取任务。当deque为空时线程会从另一个繁忙线程的deque尾部获取任务或者从全局入口队列获取任务因为那里可能存放着最大的工作块。 这种方式最大程度地减少了线程竞争任务的可能性。它还减少了线程寻找任务的次数因为首先处理最大的可用工作块。 5.2.2 CompletableFuture使用ForkJoinPool的原因 主要原因时因为它的执行模型和任务分割方式与ForlJoinPool更加匹配。 在CompletableFuture中一个任务可以分割成多个子任务并且这些子任务之间可以存在依赖关系。而ForkJoinPool本身就是一种支持任务分割和合并的线程池实现能够自动地处理任务的拆分和合并。而且ForkJoinPool还有一种工作窃取算法能够自动地调整线程的负载提高线程的利用率和并行度。 ForkJoinPool还有一个特点就是它的线程池大小是动态调整的。当任务比较小时线程池的大小会自动缩小从而减少线程的数量和占用的系统资源。当任务比较多时线程池的大小会自动增加从而保证任务能够及时地得到执行。 如果使用ExcutorService来执行这些任务需要手动地创建线程池、任务队列和任务执行策略并且需要手动地处理任务的拆分和合并实现起来比较复杂。 End希望对大家有所帮助如果有纰漏或者更好的想法请您一定不要吝啬你的赐教。
http://wiki.neutronadmin.com/news/224572/

相关文章:

  • 网站系统开发团队简介宜春公司网站建设
  • 找网站建设的企业公司网站建设实施方案
  • 甘肃网络公司网站建设甘肃定西校园文化设计公司
  • 医院网站建设的规划 百度一下
  • 做推文的编辑网站网站建设相关优化
  • 网站建设公司 预算可以做描文本的网站
  • 郑州网站建设 seodz增加网站标签
  • 现在做什么网站好产品平面广告设计
  • 五金网站方案企业宣传网站建设内容
  • 唐山网站设计公司天津营销型网站建设公司
  • seo排行榜年度10佳网站苍溪规划和建设局网站
  • 用什么程序做网站最好优化个人网站源代码下载
  • 免费做网站哪里有免费ftp服务器空间
  • 网站营销方法学习网首页
  • 网站建设高校怎样做淘客网站
  • 做网站工作条件做新闻微网站有哪些方面
  • 北京市两学一做网站wordpress更改链接后网站打不开
  • 平台制作专业网站制作如何做网站轮播图和菜单全屏
  • 汽配网站开发wordpress导入数据库
  • 珠海网站建设维护网站设计评价
  • 电子商务网站建设实训实践总结wordpress迁服务器
  • 专业做医院网站vs2010网站开发登录代码
  • 诗人做的网站公司内部网站建设
  • 邢台做网站的价格究竟多少钱?wordpress的首页
  • 网站关键词的选择培训机构招生方案范文
  • 照片一键生成视频的软件怀化百度整站优化服务
  • 龙华建网站商城网站设计公司
  • 企业网站开发公司-北京公司延边州住房城乡建设局网站
  • 做网站的疑问有哪些网站建设售后服务合同
  • 做视频网站广告收费惠州自动seo