![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
java
Code speaking
这个作者很懒,什么都没留下…
展开
-
性能 和 扩张性 - 性能 - 性能对扩展性
性能分 好快 和 多大的量。扩展性(scalability)是指加了cpu和内存,吞吐量能提高的度传统的性能优化,是用同样的资源,更快的做事,比如加缓存和优化算法。扩展性优化是扩展资源,做更多的事。提升性能(performance)和提高扩展性(scalability)是不同的两个问题。有时他们会彼此相左。为了提高扩展性,我们常常会增加单个任务的工作量。比如三层结构MVC就是这种情况。如果是单机的话,吞吐量到达了顶峰,就可以考虑扩展了 来处理更多的任务。扩展性通常更受关注,相比提高单原创 2021-07-02 15:38:19 · 735 阅读 · 2 评论 -
性能 和 扩张性 - 性能
资源:CPU cycles, memory, network bandwidth, I/O bandwidth, database requests, disk space。好的多线程,会让系统更快,吞吐更多;反之,则不然。资源需要高利用率;或者让更多的资源参加计算。cpu需要高负荷运算,不然加cpu也没用。...原创 2021-06-29 17:55:34 · 73 阅读 · 0 评论 -
不要死掉 - 避免死锁
尽量只用一个锁。如果用到多个锁,文档记录获取顺序。看有没有死锁,首先找同时请求多个锁的方法,看这些被请求锁的获取顺序是否一致。尽量用 open calls,这样定位多个锁的使用和使用顺序就简单很多。...原创 2021-06-29 15:11:11 · 54 阅读 · 0 评论 -
不要死掉 - 死锁 - open calls
Taxi 和 dispatcher 构成了死锁。去访问带锁的方法,有风险:open calls 意思是被访问的方法 没带锁。我们应该尽量使用 open calls,这样,我们比较好判断锁的顺序是否一致。缩小 synchronized block 有时候会避免死锁:调用外部包含锁的方法,不利于诊断死锁。...原创 2021-06-29 14:11:58 · 135 阅读 · 0 评论 -
不要死掉 - 死锁 - 由协作对象之间产生的死锁
例子:原创 2021-06-29 10:58:43 · 61 阅读 · 0 评论 -
不要死掉 - 死锁 - 动态锁顺序的死锁
如图,从一个账户转钱到另一个账户:如果两个线程,一个是x转y,另一个是y转x,死锁就会发生。这种情况,关键还是固定获取锁的顺序。使用System.identityHashCode 获取对象的 hsahcode,从而来确认锁的顺序。如果两个对象的hashcode一样,则使用一个公共锁:当然,如果有现成的,比如账户编号,就用不着hashcode,会更简单。我们尽量短的时间来获取锁,但是这样的话,不容易测出来:...原创 2021-06-29 09:56:19 · 90 阅读 · 0 评论 -
不要死掉 - 死锁 - 关于顺序的死锁
两个锁,一人那一个,想要对方手上的那一个,还都不放:两个线程如果以同样的顺序去要这两个锁,就不会有问题。理这个顺序比较难原创 2021-06-28 17:43:34 · 44 阅读 · 0 评论 -
多线程 不要死掉
滥用锁,可能造成 锁次序相关的死锁问题。线程池可能有 资源相关的死锁问题。这章讨论死掉的原因和怎样避免它。原创 2021-06-28 16:31:13 · 58 阅读 · 0 评论 -
executor 总结
线程的创建和消亡:corePoolSize, maPoolSize 和 keepAliveTime处理排队的 Task:放队列里超过队列长度的任务:抛弃或者让调用者执行hooks用来扩展ThreadPoolServicediscardOldest和 PriorityBlockingQueue连用可能把高优先级的丢掉有些任务,他们之间可能有线程安全问题,所以要用SingleThreadPoolService...原创 2021-06-28 16:20:48 · 47 阅读 · 0 评论 -
并发一个递归算法
生成页面那个例子,最后以并发的形式下载图片,提高了效率。迭代通常可以换成并发,只要任务是独立的,计算量大,以及存在阻塞。只要任务是独立的,就可以并发:如果要等他们执行完,调用ExecutorService.invokeAll。迭代的任务要足够大,才有必要改成并发,因为并发有开销。如果情况允许,递归也可以改成并发:caller 可以使用shutdown 和 awaitTermination 来等待计算完成:...原创 2021-06-28 15:25:56 · 217 阅读 · 0 评论 -
一个扩展 ThreadPoolExecutor的例子
记录了总时间和任务总数:原创 2021-06-28 14:59:30 · 47 阅读 · 0 评论 -
可以在 executor 被创建好以后,改变它的参数
Executor 建立好了以后,各种参数也可以修改的:有那种不能在创建后,重新设置参数的pool,如 unconfigurableExecutorService,newSingleThreadExecutor。如果你不想让pool的参数被改变,用unconfigurableExecutorService。...原创 2021-06-28 13:57:27 · 97 阅读 · 0 评论 -
Java Executor 中的线程工厂
Thread factory线程工厂接口:建立定制化的 线程工厂,来设置 UncaughtExceptionHandler 。定制化的线程工厂,加了个名字,方便debug:用定制化的线程工厂,给线程加日志,统计和UncaughtExceptionHandler:...原创 2021-06-28 11:36:30 · 325 阅读 · 0 评论 -
java executor 队列满后,任务的处理策略
如果队列满了,就需要 staturation policies 来处理装不下的 task。或者Executor已关闭,处理那些还没有执行的任务。 有各种策略:AbortPolicy, CallerRunsPolicy, DiscardPolicy, and DiscardOldestPolicy.默认是abort policy,抛弃任务,并且抛出异常(abort ExecutionException)。discard policy是直接丢弃,不抛异常。caller run policy 就是...原创 2021-06-28 11:15:06 · 549 阅读 · 0 评论 -
扩展 ThreadpoolExecutor
用有长度限制的队列,可以避免 outOfMemoryError。有种同步队列(SynchronousQueue),它会立刻把task 交给线程,如果没有线程来处理这个任务,同步队列会拒绝这个 Task。有那种先进先出(FIFO)的队列(ArrayBlockingQueue 和 LinkedBlockingQueue),也有按优先级来的队列。(priorityBlockingQueue)一般用 newCachedThreadPool, 它的性能不错。也可以选择有线程数限制的pool,可以保证稳定性原创 2021-06-28 10:25:28 · 88 阅读 · 0 评论 -
Spring AOP 概述
AOP core concepts:Joinpoints, Advice, Pointcuts, Aspects, Weaving, Target, IntroductionFour Advise types: Before Advice, After-Returning Advice, Around Advice, Throws Advicesix basic pointcut implementations:Annotation Matching Pointcuts, AspectJ Poin.翻译 2020-09-14 17:32:32 · 54 阅读 · 0 评论 -
Spring AOP AspectJ
import com.apress.prospring5.ch2.common.Guitar;import com.apress.prospring5.ch2.common.Singer;import org.springframework.stereotype.Component;@Component("johnMayer")public class GrammyGuitarist implements Singer { @Override public void sing() .翻译 2020-09-11 17:23:48 · 75 阅读 · 0 评论 -
Spring AOP demo
import com.apress.prospring5.ch2.common.Guitar; import com.apress.prospring5.ch2.common.Singer;public class GrammyGuitarist implements Singer { @Override public void sing() { System.out.println("sing: Gravity is working against me\n" .翻译 2020-09-10 17:01:26 · 65 阅读 · 0 评论 -
Spring Introduction AOP
import org.springframework.aop.support.DefaultIntroductionAdvisor;public class IsModifiedAdvisor extends DefaultIntroductionAdvisor { public IsModifiedAdvisor() { super(new IsModifiedMixin()); }}import java.lang.reflect.Method;import.原创 2020-09-10 16:26:44 · 82 阅读 · 0 评论 -
Spring AOP 检查对象状态
public interface IsModified { boolean isModified();}import java.lang.reflect.Method;import java.util.HashMap;import java.util.Map;import org.aopalliance.intercept.MethodInvocation;import org.springframework.aop.support.DelegatingIntroductionIn.翻译 2020-09-09 09:54:24 · 349 阅读 · 0 评论 -
Work Flow Pointcut 和 Composable Pointcut
import java.lang.reflect.Method;import org.springframework.aop.MethodBeforeAdvice;public class SimpleBeforeAdvice implements MethodBeforeAdvice { @Override public void before(Method method, Object args, Object target) throws Throwabl.翻译 2020-09-07 14:37:04 · 104 阅读 · 0 评论 -
CGLIB Proxy 和 JDK proxy
import java.lang.annotation.ElementType;import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;import java.lang.annotation.Target;@Retention(RetentionPolicy.RUNTIME)@Target({ElementType.TYPE, ElementType.METHOD})public @in.翻译 2020-09-07 11:23:04 · 70 阅读 · 0 评论 -
Spring AOP Pointcut
import org.springframework.aop.Advisor;import org.springframework.aop.aspectj.AspectJExpressionPointcut;import org.springframework.aop.framework.ProxyFactory;import org.springframework.aop.support.DefaultPointcutAdvisor;public class AspectjexpPointcut.翻译 2020-09-04 17:22:35 · 73 阅读 · 0 评论 -
Spring AOP 自定义 Pointcut Advice Pointcut相关类类图
Composing multiple pointcuts together Handling control flow pointcuts Performing simple name-based matching Defining pointcuts using regular expressions Defining pointcuts using AspectJ expressions Defining pointcuts that look fo..翻译 2020-09-04 11:28:44 · 406 阅读 · 0 评论 -
Spring AOP Before After Around Throws
import java.lang.reflect.Method;import org.springframework.aop.MethodBeforeAdvice;import org.springframework.aop.framework.ProxyFactory;public class SimpleBeforeAdvice implements MethodBeforeAdvice { public static void main(String... args) { .翻译 2020-09-04 10:38:49 · 99 阅读 · 0 评论 -
Spring AOP 一个简单Demo
public class Agent { public void speak() { System.out.print("Bond"); }}import org.aopalliance.intercept.MethodInterceptor;import org.aopalliance.intercept.MethodInvocation;public class AgentDecorator implements MethodInterceptor {翻译 2020-08-23 15:07:13 · 166 阅读 · 0 评论 -
Spting 配置 XML和JAVA混合配置 profile的使用 JSR330DI注解 Spring中使用Groovy
<beans> <bean id="provider" class="com.apress.prospring5.ch4.ConfigurableMessageProvider" p:message="Love on the weekend" /></beans>import com.apress.prospring5.ch2.decoupled.MessageProvider;import com.apre..翻译 2020-08-22 19:09:42 · 172 阅读 · 0 评论 -
Spring 配置 国际化 事件 资源访问 类型转化 工厂
import java.security.MessageDigest;import org.springframework.beans.factory.FactoryBean;import org.springframework.beans.factory.InitializingBean;public class MessageDigestFactoryBean implements FactoryBean<MessageDigest>, InitializingBean { .翻译 2020-08-20 10:04:57 · 131 阅读 · 0 评论 -
Activiti Configuring 和 deploying
嵌入式部署在Servelet的listener里构建ProcessEngine单独部署Rest接口两种模式应用场景:多个应用同时需要使用流程系统,用单独部署;需要定制化的流程系统,用嵌入式。监听器来初始化流程引擎<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/ac..翻译 2020-08-18 14:30:37 · 93 阅读 · 0 评论 -
Activiti Error Handling
error end event 和 error boundary eventjava 中处理异常ws设计流程图,java处理异常 结合 error end and boundary event用bpmn designer 设计在Activiti designer 上展示流程图设计分支条件配form<endEvent id="errorendevent1"> <errorEventDefinition ..翻译 2020-08-16 11:43:05 · 143 阅读 · 0 评论 -
Spring Aware 接口 实现
import org.springframework.beans.factory.BeanNameAware;public class NamedSinger implements BeanNameAware { private String name; /** @Implements {@link BeanNameAware#setBeanName(String)} */ public void setBeanName(String beanName) { t.翻译 2020-08-15 16:04:36 · 84 阅读 · 0 评论 -
Spring Bean 的 destroy方法配置
import java.io.File;import org.springframework.beans.factory.InitializingBean;import org.springframework.context.support.GenericXmlApplicationContext;public class DestructiveBean implements InitializingBean { private File file; private String f.翻译 2020-08-15 15:44:24 · 804 阅读 · 0 评论 -
Spring Bean的创建
import org.springframework.beans.factory.BeanCreationException;import org.springframework.context.ApplicationContext;import org.springframework.context.support.GenericXmlApplicationContext;public class Singer { private static final String DEFAULT_.翻译 2020-08-15 15:22:13 · 145 阅读 · 1 评论 -
Activiti 子流程
子流程非独立子流程独立子流程非独立子流程引入非独立子流程独立子流程可供多个流程使用使用CallActiviti 调用独立子流程翻译 2020-08-13 17:12:05 · 565 阅读 · 1 评论 -
Spring IOC 4
import org.springframework.core.annotation.AliasFor;@Awardpublic @interface Trophy { @AliasFor(annotation = Award.class, attribute = "value") String name() default {};}import org.springframework.stereotype.Component;@Component("john.翻译 2020-08-12 14:58:29 · 81 阅读 · 0 评论 -
Spring IOC 4
import org.springframework.beans.factory.annotation.Value;import org.springframework.context.support.GenericXmlApplicationContext;import org.springframework.stereotype.Service;@Service("injectSimple")public class InjectSimple { @Value("John Ma.翻译 2020-08-11 15:17:46 · 115 阅读 · 0 评论 -
实现 BPMN2.0 流程 2
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg. StandaloneInMemProcessEngineConfiguration"> <property name="databaseSchemaUpdate" value="true"/> <property name="history" value="full" /&g.翻译 2020-08-10 17:42:10 · 411 阅读 · 0 评论 -
实现一个 BPMN2.0 流程 1
一个贷款的流程Check credit 是脚本;Create application是调用Java服务<script> sum = 0; for ( i in inputArray ) { sum += i }</script>inputArray是process variable<script> def bookVar = "BPMN 2.0 with Activiti" executio..翻译 2020-08-10 16:50:53 · 324 阅读 · 0 评论 -
Spring IOC 3
<beans ...> <bean id="renderer" class="com.apress.prospring5.ch2.decoupled.StandardOutMessageRenderer"> <property name="messageProvider" ref="provider"/> </bean> <bean id="provider" class="com.翻译 2020-08-10 16:51:14 · 75 阅读 · 0 评论 -
Spring IOC2
Spring的依赖注入实现public interface Oracle { String defineMeaningOfLife();}public class BookwormOracle implements Oracle { private Encyclopedia encyclopedia; public void setEncyclopedia(Encyclopedia encyclopedia) { this.encyclopedia = en.翻译 2020-08-09 10:40:09 · 81 阅读 · 0 评论