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

seo网站设计工具网站发布

seo网站设计工具,网站发布,wordpress分类目录消失,扁平式的网站在Java7在。JDK它提供了多线程开发提供了一个非常强大的框架。这是Fork/Join框架。这是原来的Executors更多 进一步,在原来的基础上添加了并行分治计算中的一种Work-stealing策略。就是指的是。当一个线程正在等待他创建的 子线程执行的时候,当前线程假设…

在Java7在。JDK它提供了多线程开发提供了一个非常强大的框架。这是Fork/Join框架。这是原来的Executors更多

进一步,在原来的基础上添加了并行分治计算中的一种Work-stealing策略。就是指的是。

当一个线程正在等待他创建的

子线程执行的时候,当前线程假设完毕了自己的任务后,就会寻找还没有被执行的任务而且执行他们,这样就是和

Executors这个方式最大的差别,更加有效的使用了线程的资源和功能。所以很推荐使用Fork/Join框架。


以下我们以一个样例来说明这个框架怎样使用。主要就是创建一个含有10000个资源的List,分别去改动他的内容。


package com.bird.concursey.charpet8;/*** store the name and price of a product* @author bird 2014年10月7日 下午11:23:14*/
public class Product {private String name;private double price;public String getName() {return name;}public void setName(String name) {this.name = name;}public double getPrice() {return price;}public void setPrice(double price) {this.price = price;}}


package com.bird.concursey.charpet8;import java.util.ArrayList;
import java.util.List;/*** generate a list of random products* @author bird* 2014年10月7日 下午11:24:47*/
public class ProductListGenerator {public List<Product> generate(int size) {List<Product> list = new ArrayList<Product>();for(int i = 0 ; i < size; i++) {Product product = new Product();product.setName("Product" + i);product.setPrice(10);list.add(product);}return list;}
}


package com.bird.concursey.charpet8;import java.util.List;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveAction;
import java.util.concurrent.TimeUnit;public class Task extends RecursiveAction {private static final long serialVersionUID = 1L;// These attributes will determine the block of products this task has to// process.private List<Product> products;private int first;private int last;// store the increment of the price of the productsprivate double increment;public Task(List<Product> products, int first, int last, double increment) {super();this.products = products;this.first = first;this.last = last;this.increment = increment;}/*** If the difference between the last and first attributes is greater than* or equal to 10, create two new Task objects, one to process the first* half of products and the other to process the second half and execute* them in ForkJoinPool using the invokeAll() method.*/@Overrideprotected void compute() {if (last - first < 10) {updatePrices();} else {int middle = (first + last) / 2;System.out.printf("Task: Pending tasks:%s\n", getQueuedTaskCount());Task t1 = new Task(products, first, middle + 1, increment);Task t2 = new Task(products, middle + 1, last, increment);invokeAll(t1, t2);}}private void updatePrices() {for (int i = first; i < last; i++) {Product product = products.get(i);product.setPrice(product.getPrice() * (1 + increment));}}public static void main(String[] args) {ProductListGenerator productListGenerator = new ProductListGenerator();List<Product> products = productListGenerator.generate(10000);Task task = new Task(products, 0, products.size(), 0.2);ForkJoinPool pool = new ForkJoinPool();pool.execute(task);do {System.out.printf("Main: Thread Count: %d\n",pool.getActiveThreadCount());System.out.printf("Main: Thread Steal: %d\n", pool.getStealCount());System.out.printf("Main: Parallelism: %d\n", pool.getParallelism());try {TimeUnit.MILLISECONDS.sleep(5);} catch (InterruptedException e) {e.printStackTrace();}} while (!task.isDone());pool.shutdown();if(task.isCompletedNormally()) {System.out.printf("Main: The process has completed normally.\n");}for(Product product : products) {if(product.getPrice() != 12) {System.out.printf("Product %s: %f\n",product.getName(),product.getPrice());}}System.out.println("Main: End of the program.\n");}}


In this example, you have created a ForkJoinPool object and a subclass of the
ForkJoinTask class that you execute in the pool. To create the ForkJoinPool object,
you have used the constructor without arguments, so it will be executed with its default
configuration. It creates a pool with a number of threads equal to the number of processors
of the computer. When the ForkJoinPool object is created, those threads are created and
they wait in the pool until some tasks arrive for their execution.


Since the Task class doesn't return a result, it extends the RecursiveAction class. In the
recipe, you have used the recommended structure for the implementation of the task. If the
task has to update more than 10 products, it divides those set of elements into two blocks,
creates two tasks, and assigns a block to each task. You have used the first and last
attributes in the Task class to know the range of positions that this task has to update in the
list of products. You have used the first and last attributes to use only one copy of the
products list and not create different lists for each task.


To execute the subtasks that a task creates, it calls the invokeAll() method. This is a
synchronous call, and the task waits for the finalization of the subtasks before continuing
(potentially finishing) its execution. While the task is waiting for its subtasks, the worker thread
that was executing it takes another task that was waiting for execution and executes it. With
this behavior, the Fork/Join framework offers a more efficient task management than the
Runnable and Callable objects themselves.


The invokeAll() method of the ForkJoinTask class is one of the main differences
between the Executor and the Fork/Join framework. In the Executor framework, all the tasks
have to be sent to the executor, while in this case, the tasks include methods to execute and
control the tasks inside the pool. You have used the invokeAll() method in the Task class,
that extends the RecursiveAction class that extends the ForkJoinTask class.

You have sent a unique task to the pool to update all the list of products using the execute()
method. In this case, it's an asynchronous call, and the main thread continues its execution.
You have used some methods of the ForkJoinPool class to check the status and the
evolution of the tasks that are running. The class includes more methods that can be useful
for this purpose. See the Monitoring a Fork/Join pool recipe for a complete list of
those methods.

Finally, like with the Executor framework, you should finish ForkJoinPool using the
shutdown() method.

版权声明:本文博客原创文章,博客,未经同意,不得转载。

http://www.lbrq.cn/news/2785879.html

相关文章:

  • 帝国 只做网站地图广告代理公司
  • 做微网站的公司哪家好呢怎么出售友情链接
  • 怎么做好网站营销40个免费靠谱网站
  • 淄博网站优化平台推广策略都有哪些
  • 上海网站建设流网站建设公司地址在哪
  • 哪里有网站推广软件怎么找关键词
  • 顶岗实践网站开发东莞seo网络优化
  • 西宁软件优化网站建设app开发需要多少钱
  • 重庆免费推广网站怎样推广
  • 国外专门用于做网站图片的北京疫情消息1小时前
  • 沈阳建站seo检测优化
  • 青海省建设厅网站首页关键词优化公司
  • 帝国cms 网站例子谷歌建站
  • 做的网站怎么上传到网上运行win7优化大师官方免费下载
  • 一个wordpress多个网站网络优化主要做什么
  • 富利建设集团有限公司网站千锋教育培训机构就业率
  • 优化后的网站百度seo优化教程免费
  • 网站左右箭头素材成人大学报名官网入口
  • 网站建设需要哪些准备网络推广的方式
  • 佛山大良网站建设招聘百度网盘电脑版
  • 汉阴网站建设排行榜百度
  • 黄石做企业网站搜狐综合小时报2022113011
  • 有了域名后怎么完成网站建设广告投放是做什么的
  • 公司简介范文100字左右自建站seo如何做
  • 越秀网站建设优化坚持
  • 格尔木市公司网站建设比较成功的网络营销案例
  • 博罗网站建设哪家好军事新闻
  • 通辽企业网站建设b站推广网站2023
  • 校园二手网站设计论文一句话让客户主动找你
  • 网站制作素材网站泉州百度网站推广
  • (第二十五节课内容总结)
  • 项目各功能介绍
  • wpf之ComboBox
  • 从繁琐到优雅:Java Lambda 表达式全解析与实战指南
  • LeetCode算法日记 - Day 16: 连续数组、矩阵区域和
  • 推理还是训练 || KV缓存和CoT技术