executor

Executor and Daemon in Java

无人久伴 提交于 2019-11-27 02:23:58
问题 I have a MyThread object which I instantiate when my app is loaded through the server, I mark it as a Daemon thread and then call start() on it. The thread is meant to sit and wait for information from a queue as long as the application is active. My problem/question is this: Currently MyThread is extending Thread because I mark it as Daemon and I read about how it's more prefferable to implement Runnable and to use Executors. So what I wanted to ask is if MyThread will implement Runnable

SPARK调优之资源分配

天大地大妈咪最大 提交于 2019-11-26 22:27:31
分配更多资源:性能调优的王道,就是增加和分配更多的资源,性能和速度上的提升,是显而易见的 1、分配哪些资源? executor、cpu per executor、memory per executor、driver memory 2、在哪里分配这些资源? 在我们在生产环境中,提交spark作业时,用的spark-submit shell脚本,里面调整对应的参数 3、调节到多大,算是最大呢? 一个原则,能使用的资源有多大,就尽量去调节到最大的大小(executor的数量,几十个到上百个不等;executor内存;executor cpu core) 来源: https://www.cnblogs.com/xiangyuguan/p/11333960.html

How to implement PriorityBlockingQueue with ThreadPoolExecutor and custom tasks

天涯浪子 提交于 2019-11-26 22:20:53
问题 I've searched a lot but could not find a solutuion to my problem. I have my own class, BaseTask , that uses a ThreadPoolExecutor to handle tasks. I want task prioritization, but when I try to use a PriorityBlockingQueue I get ClassCastException because the ThreadPoolExecutor wraps my Tasks into a FutureTask object. This obviously makes sense because the FutureTask does not implement Comparable , but how would I go on to solve the priority problem? I've read that you could override newTaskFor(

mybatis源码分析之SqlSession的创建过程

旧城冷巷雨未停 提交于 2019-11-26 20:54:56
mybatis之SqlSessionFactory mybatis源码分析之Configuration mybatis源码分析之事务管理器 以上是之前的分析,在 mybatis源码分析之事务管理器 里分析到了事务管理器 SqlSession session = sqlSessionFactory.openSession(); //DefaultSqlSessionFactory里的openSession public SqlSession openSession() { return openSessionFromDataSource(configuration.getDefaultExecutorType(), null, false); } private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) { Transaction tx = null; try { //根据配置获取环境 final Environment environment = configuration.getEnvironment(); //构建事务工厂 final TransactionFactory

Mybatis3.3.x技术内幕(五):Executor之doFlushStatements()

我们两清 提交于 2019-11-26 20:35:08
这天气,热的我满头大蒜。 在上一篇博文 ‍ ‍ ‍ ‍ 《五鼠闹东京之执行器Executor设计原本》 ‍ ‍ ‍ ‍ 中,已经对 Executor做了比较详细的分析,但是,测试妹纸阅读完后,表示某些地方看不懂,毫不客气的给我提出了两点修改意见。 一、看完你的Statement和PrepareStatement批处理原理图,依然不明白为何一个编译Sql 3次,而另外一个编译Sql 1次。 二、对关闭Statement对象一笔带过,不够清晰。 我准备亡羊补牢,针对上面的两个问题进行补充完善。 1.Statement和PrepareStatement在批处理时对Sql的编译策略 insert into students(id) values(1); insert into students(id) values(1); insert into students(id) values(2); insert into students(id) values(3); 上面的4个Sql,无论是Statement,还是PrepareStatement,对Sql都编译3次。因为其中第1、2条Sql是完全相同的,只会编译1次。 insert into students(id) values(?); // id=[1,2,3] 对于 PrepareStatement,支持问号“?”占位符

设计模式--命令模式

梦想与她 提交于 2019-11-26 19:10:18
设计模式:命令模式 重点:   传递命令,执行器执行命令。 线程类:Executor 就是使用的命令模式。 源码:     public interface Executor {     void execute(Runnable command);   } 额外的话题:      线程工厂的意义:     解耦   原有的创建线程方式:创建线程和需要执行的任务耦合。   使用线程工厂的方式:创建线程用线程工厂,需要执行的任务与创建线程解耦。 来源: https://www.cnblogs.com/chen--biao/p/11330465.html

Method call to Future.get() blocks. Is that really desirable?

梦想的初衷 提交于 2019-11-26 18:56:24
问题 Please read the question carefully before marking this as duplicate. Below is the snippet of the pseudo code. My question is- Does the below code not defeat the very notion of parallel asynchronous processing? The reason I ask this is because in the below code the main thread would submit a task to be executed in a different thread. After submitting the task in the queue, it blocks on Future.get() method for the task to return the value. I would rather have the task executed in the main

What is optimum thread pool size for simple program running cpu based tasks in Java

做~自己de王妃 提交于 2019-11-26 18:19:19
问题 Im using a thread pool to execute tasks , that are mostly cpu based with a bit of I/O, of size one larger than the number of cpus. Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1) Assuming case of simple program that submits all its tasks to this executor and does little else I assume having a thread pool any larger would slow things because the OS would have to timeslice it cpus more often chance to give each thread in the threadpool a chance to run. Is that

ava引用类型原理深度剖析

半腔热情 提交于 2019-11-26 17:08:12
Java中一共有4种引用类型(其实还有一些其他的引用类型比如FinalReference):强引用、软引用、弱引用、虚引用。其中强引用就是我们经常使用的Object a = new Object(); 这样的形式,在Java中并没有对应的Reference类。 本篇文章主要是分析软引用、弱引用、虚引用的实现,这三种引用类型都是继承于Reference这个类,主要逻辑也在Reference中。 问题 在分析前,先抛几个问题? 1.网上大多数文章对于软引用的介绍是:在内存不足的时候才会被回收,那内存不足是怎么定义的?什么才叫内存不足? 2.网上大多数文章对于虚引用的介绍是:形同虚设,虚引用并不会决定对象的生命周期。主要用来跟踪对象被垃圾回收器回收的活动。真的是这样吗? 3.虚引用在Jdk中有哪些场景下用到了呢? Reference 我们先看下Reference.java中的几个字段 public abstract class Reference { //引用的对象 private T referent; //回收队列,由使用者在Reference的构造函数中指定 volatile ReferenceQueue<? super T> queue; //当该引用被加入到queue中的时候,该字段被设置为queue中的下一个元素,以形成链表结构 volatile Reference next

Removing all queued tasks of an ThreadPoolExecutor

天大地大妈咪最大 提交于 2019-11-26 16:23:08
问题 i have this rather simple question about the ThreadPoolExecutor. I have the following situation: I have to consume objects from a queue, create the appropiate worker tasks for them and submit them to the ThreadPoolExecutor. This is quite simple. But within a shutdown scenario many workers may be queued to execution. Since one of those tasks might be running for an hour, and i want a relativly fast graceful shutdown of the application i want to discard all queued tasks from the