2021
2020
java nio select 与 go select,python select
https://docs.python.org/3.8/library/select.html
library
https://mvnrepository.com/open-source?p=15
https://java.libhunt.com/
http://latencyutils.org/
https://www.jfrogchina.com/
explore exchange-web-api jar
benchmark
https://k6.io/blog/comparing-best-open-source-load-testing-tools
web压测考虑这个: https://www.locust.io/
robotframework 和cucumber
Classloader
https://docs.oracle.com/javase/8/docs/api/index.html?java/lang/ClassLoader.html https://tomcat.apache.org/tomcat-9.0-doc/class-loader-howto.html https://maven.apache.org/guides/mini/guide-maven-classloading.html https://dzone.com/articles/spring-boot-classloader-and-class-override https://en.wikipedia.org/wiki/Java_Classloader https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/lang/ClassLoader.html https://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/4/html/Inside_the_JBoss_Class_Loading_Architecture-The_Complete_Class_Loading_Model.html https://www.jrebel.com/blog/how-to-use-java-classloaders https://www.eclipse.org/jetty/documentation/current/jetty-classloading.html
https://sites.google.com/site/sureshdevang/java-classloader-hierarchy Java容器隔离简介 https://wemp.app/posts/c2b76b5b-af28-434b-8a02-29f2ba658b45 https://github.com/kevinlynx/kcontainer http://codemacro.com/2015/09/05/java-lightweight-container/ ClassLoaders are used in large systems and server applications to do things like: Modularize a system and load, unload and update modules at runtime Use different versions of an API library (e.g. an XML parser) in parallel Isolate different applications running within the same JVM (ensuring they don't interfere with each other, e.g. through static variables) https://github.com/sofastack/sofa-ark
https://github.com/rzwitserloot/lombok/blob/master/src/launch/lombok/launch/ShadowClassLoader.java
一系列文章:https://dzone.com/articles/reloading-java-classes-401
RJC101: Objects, Classes and ClassLoaders RJC201: How do Classloader leaks happen? RJC301: Classloaders in Web Development — Tomcat, GlassFish, OSGi, Tapestry 5 and so on RJC401: HotSwap and JRebel — Behind the Scenes RJC501: How Much Does Turnaround Cost?
ClassLoader Leak https://arthas.aliyun.com/doc/classloader.html
[arthas@27028]$ classloader name numberOfInstances loadedCountTotal sun.misc.Launcher$AppClassLoader 1 6383 BootstrapClassLoader 1 3087 com.taobao.arthas.agent.ArthasClassloader 1 1210 sun.reflect.DelegatingClassLoader 253 253 sun.misc.Launcher$ExtClassLoader 1 30 javax.management.remote.rmi.NoCallStackClassLoader 2 2 sun.reflect.misc.MethodUtil
sun/reflect/GeneratedMethodAccessor类和sun/reflect/DelegatingClassLoader private ClassLoader contextClassLoader 反射原理:https://mp.weixin.qq.com/s/5H6UHcP6kvR2X5hTj_SBjA
Collections
2021-01-04
集合选择:关键看新加了哪些Collection?有什么新的特性? 对比:Apache Common Collection4,Guava,Varv,JCF,Eclipse Collections 像Guava,Apache Common Collection4和JCF比较像,但是EC和vavr就差别比较大,设计里面也不同。
https://www.eclipse.org/collections/
https://github.com/eclipse/eclipse-collections
Javaslang https://docs.vavr.io/#_introduction
动态代理
线上问题之动态代理失效,导致AOP失效,Redis分布式锁没有释放。
CGLib和JDK区别? 将项目的一个方法写成了final,启动时候异常,运行时注入的类是空的: o.s.aop.framework.CglibAopProxy - Unable to proxy interface-implementing method [public final java.util.Set com.chainup.cache.redis.RedisClientTemplate.keys(java.lang.String)] because it is marked as final: Consider using interface-based JDK proxies instead!
动态代理+分布式锁组合造成了充值阻塞了几百笔,事故时间长达2小时。
动态代理给所有实现类,加代理行为怎么加呢?CGLIB? JDK只能传入一个实现类,获取他的代理的方式。 动态代理给指定类,加代理行为怎么加呢?
https://docs.spring.io/spring-framework/docs/2.5.x/reference/aop.html#aop-proxying
动态代理方法和类,构造函数,
CGLIB不能代理final方法 https://jira.spring.io/browse/SPR-15436?redirect=false
https://github.com/spring-projects/spring-framework/issues/7798
https://dzone.com/articles/cglib-missing-manual
https://www.cnblogs.com/onlymate/p/9630788.html
https://www.choupangxia.com/2019/11/06/spring-cglib2aopproxy/
https://github.com/spring-projects/spring-boot/issues/8974
https://github.com/spring-projects/spring-framework/issues/19997
https://stackoverflow.com/questions/39590094/spring-aop-proxy-and-interface-implementation
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
但是改成接口代理的话,启动又会报错: 在属性文件中加入,改成了接口代理。 spring.aop.proxy-target-class=false
会报错:
2020-12-31 16:19:00.389 [main] WARN o.s.w.c.s.GenericWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'configAccountTypeServiceImpl': Unsatisfied dependency expressed through field 'redisClient'; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'redisClientTemplate' is expected to be of type 'com.chainup.cache.redis.RedisClientTemplate' but was actually of type ' com.sun.proxy.$Proxy156' 2020-12-31 16:19:00.427 [main] INFO o.s.b.a.l.ConditionEvaluationReportLoggingListener -
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2020-12-31 16:19:00.435 [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter -
APPLICATION FAILED TO START
Description:
The bean 'redisClientTemplate' could not be injected as a 'com.chainup.cache.redis.RedisClientTemplate' because it is a JDK dynamic proxy that implements: com.chainup.cache.redis.core.RedisClient
Action:
Consider injecting the bean as one of its interfaces or forcing the use of CGLib-based proxies by setting proxyTargetClass=true on @EnableAsync and/or @EnableCaching.
2020-12-31 16:19:00.443 [main] ERROR o.s.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@6692b6c6] to prepare test instance [com.chainup.exchange.service.RedisClientTemplateTest@fd5689d] java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext( DefaultCacheAwareContextLoaderDelegate.java:132) at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:123) at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary( ServletTestExecutionListener.java:190) at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance( ServletTestExecutionListener.java:132) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:244) at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:98) at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeTestInstancePostProcessors$5( ClassTestDescriptor.java:349) at org.junit.jupiter.engine.descriptor.JupiterTestDescriptor.executeAndMaskThrowable(JupiterTestDescriptor.java:215) at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeTestInstancePostProcessors$6( ClassTestDescriptor.java:349) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:312) at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:743) at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:742) at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580) at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.invokeTestInstancePostProcessors(ClassTestDescriptor.java: 348) at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.instantiateAndPostProcessTestInstance( ClassTestDescriptor.java:270) at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$2(ClassTestDescriptor.java:259) at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$3(ClassTestDescriptor.java:263) at java.util.Optional.orElseGet(Optional.java:267) at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$4(ClassTestDescriptor.java:262) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:82) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:59) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$0(NodeTestTask.java:83) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72) at org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.java:83) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:69) at java.util.ArrayList.forEach(ArrayList.java:1257) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll( SameThreadHierarchicalTestExecutorService.java:38) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74) at java.util.ArrayList.forEach(ArrayList.java:1257) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll( SameThreadHierarchicalTestExecutorService.java:38) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit( SameThreadHierarchicalTestExecutorService.java:32) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57) at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220) at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188) at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128) at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58) Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ' configAccountTypeServiceImpl': Unsatisfied dependency expressed through field 'redisClient'; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'redisClientTemplate' is expected to be of type 'com.chainup.cache.redis.RedisClientTemplate' but was actually of type 'com.sun.proxy.$Proxy156'
因为属性类通过接口引用的类。
事件总线
Observable,Observer SwingUtilities,SwingWorker EventListenerList,EventObject,EventListener Message driven - Guava (by Google)
interface ActionListener { void actionPerformed(ActionEvent e); }
JButton button = new JButton("Click me"); button.addActionListener((e) -> System.out.println("Button clicked") )
hash
2021-01-04
https://www.zhihu.com/question/286529973
HashMap平衡树?https://openjdk.java.net/jeps/180
https://en.wikipedia.org/wiki/SipHash
https://www.slideshare.net/stamparm/hash-dos-attack
https://www.geeksforgeeks.org/string-hashing-using-polynomial-rolling-hash-function/
String多项式Hash算法
雪崩效应
Hash Flooding
Avalance Effect
HashDoS
https://en.wikipedia.org/wiki/Cache_stampede
JDBC
DriverManager,ServiceLoader,ClassLoader,
online question
线上问题经典待整理博客: 1 事务失效,数据源切换失败。
2 动态代理不能代理final方法,分布式锁释放失败,充提挂了。
3 forkjoin不正确使用导致线程hang住,系统突然卡死,定时任务不在执行。
4 内存泄漏问题,没有重写hashCode方法导致内存泄漏。
5 ThreadLocal内存泄漏问题。
6 Redis带宽被打满,热点key问题
7 Broken pipe问题解决
8 工程方面。
ThreadLocal
博客写ThreadLocal,相关使用,log4j ThreadContext,design,利用threadlocal解决SimpleDateFormat解决线程不安全的问题
https://rules.sonarsource.com/java/type/Bug/RSPEC-5164?search=ThreadLocal
https://errorprone.info/bugpattern/ThreadLocalUsage
ThreadLocal Idea FindUsage
https://laliluna.com/jpa-hibernate-guide/ch13s04.html
HibernateSessionFactory
https://cwiki.apache.org/confluence/display/TOMCAT/MemoryLeakProtection
https://dzone.com/articles/memory-leak-protection-tomcat
FastThreadLocal
RequestContextHolder
Timer
hierarchical timer wheel
时间轮算法:https://github.com/ben-manes/caffeine/blob/master/caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java
kafka.utils.timer.SystemTimer
https://cwiki.apache.org/confluence/display/KAFKA/Purgatory+Redesign+Proposal
https://netty.io/4.0/api/io/netty/util/HashedWheelTimer.html
Timer,TimerTask VS ScheduledThreadPoolExecutor VS HashedWheelTimer
ScheduledThreadPoolExecutor VS HashedWheelTimer
Timer和WheelTimer使用场景?
https://github.com/Spikhalskiy/hashed-wheel-timer
Reinventing the timer wheel:https://lwn.net/Articles/646950/
Akka:https://doc.akka.io/docs/akka/current/scheduler.html
spring scheduler
潘爱明
《大道至易——实践者的思想》(第二版) 《程序原本》 《我的架构思想——基本模型、理论与原则》
atomix
https://atomix.io/docs/latest/user-manual/introduction/what-is-atomix/