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

网站网络设计是怎么做的百度权重提升

网站网络设计是怎么做的,百度权重提升,html5的网站,南昌公司注册代办多线程创建的五种方式: 继承Thread类实现runnable接口。实现Callable接口 FutureTask(可以拿到返回结果,阻塞式等待。)线程池创建。 ExcutorService service Excutors.newFixedThreadPool(10); service.excute(new Runnable01());另外一种创建线程池…

多线程创建的五种方式:

  1. 继承Thread类
  2. 实现runnable接口。
  3. 实现Callable接口 + FutureTask(可以拿到返回结果,阻塞式等待。)
  4. 线程池创建。
ExcutorService service = Excutors.newFixedThreadPool(10);
service.excute(new Runnable01());
  1. 另外一种创建线程池的方式:
ThreadPoolExecutor executor = new ThreadPoolExcutor();// 七大参数:
corePoolSize:核心线程数
maximumPoolSize:最大线程数
keepAliveTime:线程最大回收时间。即线程空闲的最大时间。超过该时间就销毁。
unit:时间单位。回收线程的时间的单位。
workQueue:阻塞队列。当核心线程数满了,剩余的线程将在阻塞队列中等待。
threadFactory:创建线程的工厂。
RejectedExecutionHandler:核心线程满了,阻塞队列中也满了,同时额外建立的非核心线程数(最大线程数-核心线程数)也都用完了,此时将采取拒绝策略。
max都执行完成,有很多空闲。在指定的时间keepAliveTime以后,就会释放max-core这些线程。
LinkedBlockingQueue:默认大小是Integer的最大值。可能导致内存不足。
// 核心线程数为0 , 非核心线程数是Integer的最大值。所有线程都可回收。
Executors.newCachedThreadPool();// 固定线程池,核心线程数和最大线程数一样,都是传入的值。  核心=最大,都一直不会回收
Executors.newFixedThreadPool(10);// 做定时任务调度的线程池。
Executors.newScheduledThreadPool(10);// 单线程的线程池,后台从队列中获取任务,挨个执行。
Executors.newSingleThreadExecutor()

异步编排

创建异步编排对象

CompletableFuture.runAsync(() -> {} , executorService);CompletableFuture.supplyAsync(() -> {} , executorService);

supply开头:这种方法,可以返回异步线程执行之后的结果
run开头:这种不会返回结果,就只是执行线程任务

  • CompletableFuture.whenComplete():感知异步线程的执行结果。但是无法返回。
  • CompletableFuture.exceptionally():处理异常,只要有异常,会进入该方法处理。然后返回一个对应的结果。
  • CompletableFuture.handle():用于处理返回结果,可以接收返回值和异常,可以对返回值进行修改。
CompletableFuture<String> stringCompletableFuture = CompletableFuture.supplyAsync(() -> {return "hello";
}, executorService).whenCompleteAsync((res , throwable) -> {System.out.println("stringCompletableFuture whenCompleteAsync:" + res);throw new RuntimeException("hhhhhh");
}, executorService).exceptionally((throwable) -> {return "jimo";
});System.out.println("stringCompletableFuture:" + stringCompletableFuture.get());

线程串行方法

CompletableFuture.supplyAsync(() -> {return 1;
},executorService).thenRunAsync(() -> {System.out.println("串行化执行。。。。");
} , executorService);
CompletableFuture.supplyAsync(() -> {return "n";
} , executorService).thenAcceptAsync((res) -> {System.out.println(res + "串行化:执行结果:" + res);
});
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {return "急急急";
}, executorService).thenApplyAsync((res) -> {return "ddd" + res;
});
System.out.println(future.get());
// 使线程串行执行,不感知上一线程执行的结果,也不返回当前线程执行的结果。
public CompletableFuture<Void> thenRun(Runnable action);
public CompletableFuture<Void> thenRunAsync(Runnable action);
public CompletableFuture<Void> thenRunAsync(Runnable action, Executor executor);// 使线程串行执行,感知上一线程执行的结果,不返回当前线程执行的结果。
public CompletableFuture<Void> thenAccept(Consumer<? super T> action);
public CompletableFuture<Void> thenAcceptAsync(Consumer<? super T> action);
public CompletableFuture<Void> thenAcceptAsync(Consumer<? super T> action, Executor executor);// 使线程串行执行,感知上一线程执行的结果,返回当前线程执行的结果。
public <U> CompletableFuture<U> thenApply(Function<? super T,? extends U> fn);
public <U> CompletableFuture<U> thenApplyAsync(Function<? super T,? extends U> fn);
public <U> CompletableFuture<U> thenApplyAsync(Function<? super T,? extends U> fn, Executor executor);

Async的是可以指定线程池,使用一个新的线程。
不带Async的是使用串行前面那个线程继续执行。

两任务并行执行完成,再执行新任务

CompletableFuture<Integer> future1 = CompletableFuture.supplyAsync(() -> {System.out.println("任务1正在执行。。。");return 1;
}, executorService);CompletableFuture<Integer> future2 = CompletableFuture.supplyAsync(() -> {System.out.println("任务2正在执行。。。");return 2;
}, executorService);// 两个都执行完后执行。无法获取两个任务的返回值。自己也没有返回值。
future1.runAfterBothAsync(future2 , () -> {System.out.println("两个任务都执行完了。。。");
} , executorService);// 两个任务都执行完之后执行新任务,可以获取到两个任务的返回值,自己没有返回值
future1.thenAcceptBothAsync(future2 , (res1 , res2) -> {System.out.println("两个任务都执行完了。。。");System.out.println(res1 + ":::::" + res2);
} , executorService);
// 线程并行执行完成,并且执行新任务action,新任务无入参,无返回值
public CompletableFuture<Void> runAfterBoth(CompletionStage<?> other, Runnable action);
public CompletableFuture<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action);
public CompletableFuture<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action, Executor executor);// 线程并行执行完成,并且执行新任务action,新任务有入参,无返回值
public <U> CompletableFuture<Void> thenAcceptBoth(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action);
public <U> CompletableFuture<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action);
public <U> CompletableFuture<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action, Executor executor);// 线程并行执行完成,并且执行新任务action,新任务有入参,有返回值
public <U,V> CompletableFuture<V> thenCombine(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn);
public <U,V> CompletableFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn);
public <U,V> CompletableFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn, Executor executor);

两任务执行完任意一个任务,即可执行新任务。

// 不感知执行完的线程的返回值,自己也不返回任何值。
CompletableFuture<Void> future = future1.runAfterEitherAsync(future2, () -> {System.out.println("两个任务重完成了一个任务了,可以执行新任务");
}, executorService);// 感知执行完的线程的返回值,自己也不返回任何值。
future1.acceptEitherAsync(future2 , (res) -> {System.out.println("两线程中的任意一个线程的结果:" + res);
} , executorService);// 感知执行完的线程的返回值,自己也返回值。
CompletableFuture<String> stringCompletableFuture = future1.applyToEitherAsync(future2, (res) -> {return res + "姚云峰";
}, executorService);
System.out.println(stringCompletableFuture.get());
// 任务并行执行,只要其中有一个执行完,就开始执行新任务action,新任务无入参,无返回值
public CompletableFuture<Void> runAfterEither(CompletionStage<?> other, Runnable action);
public CompletableFuture<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action);
public CompletableFuture<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor);// 任务并行执行,只要其中有一个执行完,就开始执行新任务action,新任务有入参(入参类型为Object,因为不确定是哪个任务先执行完成),无返回值
public CompletableFuture<Void> acceptEither(CompletionStage<? extends T> other, Consumer<? super T> action);
public CompletableFuture<Void> acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action);
public CompletableFuture<Void> acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action,Executor executor);// 任务并行执行,只要其中有一个执行完,就开始执行新任务action,新任务有入参(入参类型为Object,因为不确定是哪个任务先执行完成),有返回值
public <U> CompletableFuture<U> applyToEither(CompletionStage<? extends T> other, Function<? super T, U> fn);
public <U> CompletableFuture<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T, U> fn);
public <U> CompletableFuture<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T, U> fn,Executor executor);

多任务组合 都完成才返回。完成一个即返回。

// 完成一个即返回。
public static CompletableFuture<Object> anyOf(CompletableFuture<?>... cfs);
// 两任务完成1任务后即可执行。acceptEitherAsync可以感知之前的结果,自己有返回值。
CompletableFuture<String> futureImg = CompletableFuture.supplyAsync(() -> {System.out.println("查询图片信息。");return "Hello.jpg";
});CompletableFuture<String> futureAttr = CompletableFuture.supplyAsync(() -> {System.out.println("查询属性信息。");try {Thread.sleep(3000);} catch (InterruptedException e) {throw new RuntimeException(e);}return "黑色256G";
});CompletableFuture<String> futureDesc = CompletableFuture.supplyAsync(() -> {System.out.println("查询商品介绍信息。");return "华为";
});// 等待这三个都做完。
CompletableFuture<Void> all = CompletableFuture.allOf(futureImg, futureAttr, futureDesc);
System.out.println(all.get());
System.out.println("main end");
System.out.println("main end " + futureImg.get() + " " + futureAttr.get() + " " + futureDesc.get());
// 等待三个中的一个完成即可。
CompletableFuture<Object> any = CompletableFuture.anyOf(futureImg, futureAttr, futureDesc);
System.out.println(any.get());
// System.out.println("main end " + futureImg.get() + " " + futureAttr.get() + " " + futureDesc.get());
System.out.println("main end ");
http://www.hkea.cn/news/884819/

相关文章:

  • 扬中网站建设墨子学院seo
  • 分析电子商务网站建设需求教案青岛今天发生的重大新闻
  • 汕头模板开发建站百度发布信息怎么弄
  • 健身网站开发项目总结关键词筛选工具
  • 重庆网站建设零臻靠谱国内永久免费的云服务器
  • 软件库合集软件资料2024郑州百度快照优化
  • 房地产开发公司网站建设方案seo去哪里学
  • 做网站可以赚钱吗百度小说搜索风云排行榜
  • 做网站交接需要哪些权限网站seo视频教程
  • 在网站怎么做收款二维码刷移动关键词优化
  • 问信息奥赛题怎么做 去哪个网站互联网网络推广
  • b2c电子商务网站系统下载专业网站seo推广
  • 引流推广的方法seo诊断工具
  • 平阴县建设工程网站直通车推广怎么做
  • 网站开发外包不给ftp高佣金app软件推广平台
  • 太原适合网站设计地址百度用户服务中心客服电话
  • 济南源码网站建设长沙网站seo推广公司
  • 北京网站制作17页和业务多一样的平台
  • 无锡市住房城乡建设委网站简单网页设计模板html
  • 武汉市大型的网站制作公司网站ip查询
  • 做仪表行业推广有哪些网站电商网站设计
  • 动静分离网站架构百度售后客服电话24小时
  • 做汽车配件生意的网站佛山seo关键词排名
  • 创意建站推荐百度做广告多少钱一天
  • 巴中网站建设公司百度seo怎么做网站内容优化
  • 查网站备案名称上海网络营销seo
  • 人是用什么做的视频网站网络营销方案设计毕业设计
  • 建设网站考虑因素关键词优化是怎么弄的
  • 陕西营销型网站建设推广普通话的内容简短
  • 做配电箱的专门网站百度指数属于行业趋势及人群