executor

Difference between multithreading with and without Executor

馋奶兔 提交于 2019-12-09 07:04:47
问题 I am trying to find out about the performance difference between normal multithreading and multithreading using executor (to maintain a thread pool). The below are code examples for both. Without Executor Code (with multithreading): import java.lang.management.ManagementFactory; import java.lang.management.MemoryPoolMXBean; import java.lang.management.MemoryUsage; import java.lang.management.ThreadMXBean; import java.util.List; public class Demo1 { public static void main(String arg[]) {

Implementing Producer consumer pattern

ぃ、小莉子 提交于 2019-12-09 01:02:04
问题 I am trying to write a mail utility that places mails in a queue, and it is later consumed by a consumer thread. I am trying to implement a typical producer-consumer pattern, but something is going wrong. I just wrote a skeleton , and the skeleton is not working as expected. MailProducer.java public class MailProducer implements Callable<Void> { @Override public Void call() throws Exception { System.out.println("inside mail Producer"); System.out.println("Thread executing = " + Thread

Spark集群三种部署模式的区别

强颜欢笑 提交于 2019-12-07 19:48:52
Spark最主要资源管理方式按排名为Hadoop Yarn, Apache Standalone 和Mesos。在单机使用时,Spark还可以采用最基本的local模式。 目前Apache Spark支持三种分布式部署方式,分别是standalone、spark on mesos和 spark on YARN,其中,第一种类似于MapReduce 1.0所采用的模式,内部实现了容错性和资源管理,后两种则是未来发展的趋势,部分容错性和资源管理交由统一的资源管理系统完成:让Spark运行在一个通用的资源管理系统之上,这样可以与其他计算框架,比如MapReduce,公用一个集群资源,最大的好处是降低运维成本和提高资源利用率(资源按需分配)。本文将介绍这三种部署方式,并比较其优缺点。 1. Standalone模式 即独立模式,自带完整的服务,可单独部署到一个集群中,无需依赖任何其他资源管理系统。从一定程度上说,该模式是其他两种的基础。借鉴Spark开发模式,我们可以得到一种开发新型计算框架的一般思路:先设计出它的standalone模式,为了快速开发,起初不需要考虑服务(比如master/slave)的容错性,之后再开发相应的wrapper,将stanlone模式下的服务原封不动的部署到资源管理系统yarn或者mesos上,由资源管理系统负责服务本身的容错

When is specifying separate core and maximum pool sizes in ThreadPoolExecutor a good idea?

眉间皱痕 提交于 2019-12-07 04:37:40
问题 I'm trying to understand the point in specifying separate core and maximum pool sizes for Java 5's ThreadPoolExecutor. My understanding is that the number of threads is only increased once the queue is full, which seems a bit late (at least with larger queues). Isn't it that I'm either happy to allocate a larger number of threads to the tasks, in which case I might just increase the core pool size; or I am not really willing to do so, in which case I should rather have a larger queue? What is

spark-submit使用及说明

拟墨画扇 提交于 2019-12-06 19:37:02
一、命令 注意./BnmsKpiCal-0.0.1.jar包一定要放在最后面,要不然jar包后面的参数不会生效 1.向spark standalone以client方式提交job。 ./spark-submit --master spark://hadoop3:7077 --deploy-mode client --class org.apache.spark.examples.SparkPi ../lib/spark-examples-1.3.0-hadoop2.3.0.jar --deploy-mode client,在提交的节点会有个main进程,来运行Driver program。如果使用--deploy-mode cluster,则Driver program直接运行在worker中。 2.向spark on yarn以client方式提交job. ./spark-submit --master yarn --deploy-mode client --class org.apache.spark.examples.SparkPi ../lib/spark-examples-1.3.0-hadoop2.3.0.jar 二、Spark1.0.0 应用程序部署工具spark-submit 随着Spark的应用越来越广泛,对支持多资源管理器应用程序部署工具的需求也越来越迫切

Spark1.0.0 应用程序部署工具spark-submit

女生的网名这么多〃 提交于 2019-12-06 19:36:45
问题导读: 1、Spar的应用程序部署工具都提供哪些功能? 2、Spar的应用程序部署工具有哪些? 3、什么是spark-submit? 随着Spark的应用越来越广泛,对支持多资源管理器应用程序部署工具的需求也越来越迫切。Spark1.0.0的出现,这个问题得到了逐步改善。从 Spark1.0.0开始,Spark提供了一个容易上手的应用程序部署工具bin/spark-submit,可以完成Spark应用程序在 local、Standalone、YARN、Mesos上的快捷部署。 1:使用说明 进入$SPARK_HOME目录,输入bin/spark-submit --help可以得到该命令的使用帮助。 hadoop @wyy :/app/hadoop/spark100$ bin/spark-submit --help Usage: spark-submit [options] <app jar | python file> [app options] 复制代码 Options: --master MASTER_URL spark://host:port, mesos://host:port, yarn, or local. --deploy-mode DEPLOY_MODE driver运行之处,client运行在本机,cluster运行在集群 --class CLASS_NAME

【搞定面试官】你还在用Executors来创建线程池?会有什么问题呢?

跟風遠走 提交于 2019-12-06 11:49:06
摘自: https://www.cnblogs.com/LoveBell/p/11979958.html 【搞定面试官】你还在用Executors来创建线程池?会有什么问题呢? 前言 上文 我们介绍了JDK中的线程池框架 Executor 。我们知道,只要需要创建线程的情况下,即使是在单线程模式下,我们也要尽量使用 Executor 。即: ExecutorService fixedThreadPool = Executors.newFixedThreadPool(1); //此处不该利用Executors工具类来初始化线程池 但是,在 《阿里巴巴Java开发手册》 中有一条 【强制】线程池不允许使用 Executors 去创建,而是通过 ThreadPoolExecutor 的方式,这样的处理方式让写的同学更加明确线程池的运行规则,规避资源耗尽的风险。 Executors 返回的线程池对象的弊端如下: FixedThreadPool 和 SingleThreadPool : 允许的请求队列长度为 Integer.MAX_VALUE,可能会堆积大量的请求,从而导致 OOM。 CachedThreadPool 和 ScheduledThreadPool : 允许的创建线程数量为 Integer.MAX_VALUE,可能会创建大量的线程,从而导致 OOM。 可以看到

Serial Execution of multiple AsyncTasks

大兔子大兔子 提交于 2019-12-06 08:15:25
问题 Does anyone know how to easily arrange multiple calls to an AsyncTask execution in a queue or something and then execute them in a serial fashion? I want the called async task to wait while the one before it is finished, but is seems I can't accomplish this, even if I test the status of the one currently being executed. Any ideas how to solve this? I've seen that in the honeycomb API there is a method executeOnExecutor() with a SERIAL_EXECUTOR , I guess it implements what I've described.

Java原理领悟-线程池(Executor)

[亡魂溺海] 提交于 2019-12-06 06:48:00
线程池全面解析 什 么是线程池?   很简单,简单看名字就知道是装有线程的池子,我们可以把要执行的多线程交给线程池来处理,和连接池的概念一样,通过维护一定数量的线程池来达到多个线程的复用。 线程池的好处   我们知道不用线程池的话,每个线程都要通过new Thread(xxRunnable).start()的方式来创建并运行一个线程,线程少的话这不会是问题,而真实环境可能会开启多个线程让系统和程序达到最佳效率,当线程数达到一定数量就会耗尽系统的CPU和内存资源,也会造成GC频繁收集和停顿,因为每次创建和销毁一个线程都是要消耗系统资源的,如果为每个任务都创建线程这无疑是一个很大的性能瓶颈。    所以,线程池中的线程复用极大节省了系统资源,当线程一段时间不再有任务处理时它也会自动销毁,而不会长驻内存。 线程池核心类  在java.util.concurrent包中我们能找到线程池的定义,其中 ThreadPoolExecutor是我们线程池核心类,首先看看线程池类的主要参数有哪些。 corePoolSize:线程池的核心大小,也可以理解为最小的线程池大小。 maximumPoolSize:最大线程池大小。 keepAliveTime:空余线程存活时间,指的是超过corePoolSize的空余线程达到多长时间才进行销毁。 unit:销毁时间单位。 workQueue

Spark设计理念与基本架构

99封情书 提交于 2019-12-06 06:41:04
Spark设计理念与基本架构 https://www.cnblogs.com/swordfall/p/9280006.html 1.基本概念 Spark中的一些概念: RDD(resillient distributed dataset):弹性分布式数据集。 Partition:数据分区。即一个RDD的数据可以划分为多少个分区。 NarrowDependency:窄依赖,即子RDD依赖于父RDD中固定的Partition。Narrow-Dependency分为OneToOneDependency和RangeDependency两种。 ShuffleDependency:shuffle依赖,也称为宽依赖,即子RDD对父RDD中的所有Partition都有依赖。 Task:是送到某个Executor上的工作单元,即具体执行任务。Task分为ShuffleMapTask和ResultTask两种。ShuffleMapTask和ResultTask分别类似于Hadoop中的Map和Reduce。Task是运行Application的基本单位,多个Task组成一个Stage,而Task的调度和管理等是由TaskScheduler负责的。 Job:用户提交的作业。一个Job包含多个Task组成的并行计算,往往由Spark Action触发。 Stage:每个Job会被拆分成多组Task