Java
2016-09-27 14:03:54 0 举报
AI智能生成
Java是一种广泛使用的计算机编程语言,具有跨平台、面向对象、安全性高等特点。它被广泛应用于企业级应用开发、移动应用开发、游戏开发等领域。Java语言的设计目标是让程序员能够尽可能地编写一次代码,然后在不同的平台上运行,而不需要重新编译。Java提供了丰富的类库和工具,使得开发者可以快速地构建功能强大的应用。此外,Java还具有良好的安全性,它的运行时环境会自动检测并阻止恶意代码的执行。总之,Java是一种强大、灵活且易于学习的编程语言,是现代软件开发的重要工具之一。
作者其他创作
大纲/内容
JVM
内存
堆
对象,数组
GC主要工作区
栈
每个线程一个
先进后出
变量
静态,方法
class文件
头4个字节文件标识
类的内存描述,参考denfinied
Python等都可生成
gc
内存泄漏?静态对象无法回收
count标记法回收
内存置换+根路径判断
强引用,若引用
Redis
数据结构
SDS
len | fee| char[]
算法复杂度O(1)
方便扩容
双端链表
字典
跳跃表
Redis对象
RedisObject
String
哈希表
功能
事务
开始:事务状态切换
非事务状态:命令执行
事务状态:命令入队
命令入队
命令|参数|参数个数
执行:监听C破坏性
监听命令参数
其他客户修改了参数
事务检查,如果破坏就回滚
订阅与发布
一个
子主题
LUA脚本
慢查询日志
消息队列
服务端发布消息,所有的订阅者都可以收到同样的消息 = 发布/订阅
服务端生产消息,只能有一个客户端消费掉。消息就没了。其他都接收不了 = 生产/消费
<span style="color: rgb(85, 85, 85); font-family: "microsoft yahei"; font-size: 14px;">redis:listener-</span><a href="http://lib.csdn.net/base/docker" class="replace_word" title="Docker知识库" target="_blank" style="text-decoration: none; box-sizing: border-box; color: rgb(223, 52, 52); font-family: "microsoft yahei"; font-size: 14px; font-weight: bold;">Container</a>
性能快原因
绝大部分请求是纯粹的内存操作(非常快速)
采用单线程,避免了不必要的上下文切换和竞争条件
非阻塞IO
Kafka
Hbase
ZK
Cache
容量估算
失效算法
缓存穿透
缓存雪崩
RPC
像本地调用一样调用远程服务
Java动态代理达到远程调用透明化
接口封装
requestID
NIO大量的异步线程池
请求返回的唯一标识
消息队列的唯一标识
就是用来对应返回结果中那个是客户端发送的请求
序列化
<span style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">Protobuf</span>
<span style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">Thrift</span>
<span style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">Avro</span>
通信协议
netty
hessian
REST
netty+zk+<span style="color: rgb(85, 85, 85); font-family: "microsoft yahei"; font-size: 15px;">Protostuff</span>
子主题
子主题
UML
用列图
子主题
对象图
时序图
状态图
构件图
部署图
类图
JDK8
ThreadS
原子|可见|有序
Concurrent
ReentrantLock
lock();
ReadWriteLock
readLock();
writeLock();
CyclicBarrier
await();
CountDownLatch
countDown();
await();
Executors
newCachedThreadPool();
// SynchronousQueue 同步队列 所谓的缓存线程池是个伪概念,永远只有一个,会重复利用一个线程;
newFixedThreadPool(10);
10个LinkedBlockingQueue
newSingleThreadExecutor();
单个 LinkedBlockingQueue
newScheduledThreadPool(10);
定时任务
newSingleThreadScheduledExecutor();
Volatile
可见性
一个写,多个读
ConcurrentHaspMap
HashTable 全锁
锁一个单元格,8个
使用Volatile
Atomic(CAS)
sephemore
线程池大小
<div><span style="color: rgb(255, 104, 39); font-size: 17px; line-height: normal; text-align: -webkit-auto; white-space: pre-wrap; text-size-adjust: auto; margin: 0px; padding: 0px; max-width: 100%; font-family: 宋体; box-sizing: border-box !important; word-wrap: break-word !important;">单线程分析出本地计算时间为</span><span style="color: rgb(255, 104, 39); font-size: 17px; line-height: normal; text-align: -webkit-auto; white-space: pre-wrap; text-size-adjust: auto;">x</span><span style="color: rgb(255, 104, 39); font-size: 17px; line-height: normal; text-align: -webkit-auto; white-space: pre-wrap; text-size-adjust: auto; margin: 0px; padding: 0px; max-width: 100%; font-family: 宋体; box-sizing: border-box !important; word-wrap: break-word !important;">,等待时间为</span><span style="color: rgb(255, 104, 39); font-size: 17px; line-height: normal; text-align: -webkit-auto; white-space: pre-wrap; text-size-adjust: auto;">y</span></div>
<div><span style="color: rgb(255, 104, 39); font-size: 17px; line-height: normal; text-align: -webkit-auto; white-space: pre-wrap; text-size-adjust: auto; margin: 0px; padding: 0px; max-width: 100%; font-family: 宋体; box-sizing: border-box !important; word-wrap: break-word !important;">设置为</span> <span style="color: rgb(255, 104, 39); font-size: 17px; line-height: normal; text-align: -webkit-auto; white-space: pre-wrap; text-size-adjust: auto;">N*(x+y)/x; N为CPU个数</span></div>
<div><span style="color: rgb(62, 62, 62); font-size: 17px; line-height: normal; text-align: -webkit-auto; white-space: pre-wrap; text-size-adjust: auto; margin: 0px; padding: 0px; max-width: 100%; font-family: 宋体; box-sizing: border-box !important; word-wrap: break-word !important;">非</span><span style="color: rgb(62, 62, 62); font-size: 17px; line-height: normal; text-align: -webkit-auto; white-space: pre-wrap; text-size-adjust: auto;">CPU</span><span style="color: rgb(62, 62, 62); font-size: 17px; line-height: normal; text-align: -webkit-auto; white-space: pre-wrap; text-size-adjust: auto; margin: 0px; padding: 0px; max-width: 100%; font-family: 宋体; box-sizing: border-box !important; word-wrap: break-word !important;">密集型的业务(加解密、压缩解压缩、搜索排序等业务是</span><span style="color: rgb(62, 62, 62); font-size: 17px; line-height: normal; text-align: -webkit-auto; white-space: pre-wrap; text-size-adjust: auto;">CPU</span><span style="color: rgb(62, 62, 62); font-size: 17px; line-height: normal; text-align: -webkit-auto; white-space: pre-wrap; text-size-adjust: auto; margin: 0px; padding: 0px; max-width: 100%; font-family: 宋体; box-sizing: border-box !important; word-wrap: break-word !important;">密集型的业务),瓶颈都在后端数据库,本地</span><span style="color: rgb(62, 62, 62); font-size: 17px; line-height: normal; text-align: -webkit-auto; white-space: pre-wrap; text-size-adjust: auto;">CPU</span><span style="color: rgb(62, 62, 62); font-size: 17px; line-height: normal; text-align: -webkit-auto; white-space: pre-wrap; text-size-adjust: auto; margin: 0px; padding: 0px; max-width: 100%; font-family: 宋体; box-sizing: border-box !important; word-wrap: break-word !important;">计算的时间很少,设置几十或者几百个工作线程</span></div>
集合
HashMap
数组+链表
hash(key)%len = 数组下标
entry = key | value| next
int hash = key.hashCode();
int index = hash % Entry[].length;
return Entry[index];
JMS
NIO
channal
buffer
sector
子主题
BIO
子主题
DB(oracle)
锁
行锁
for update : 一直等,然后加锁
for update nowait : 不等,直接报错
for update wait 5 : 等五秒
表锁
行共享:允许用户进行任何操作,禁止排他锁
lock table person in row share mode;
行排他:允许用户进行任何操作,禁止共享锁
lock table person in row exclusive mode;
共享锁:其他用户只能看,不能修改
lock table person in share mode;
共享行排他:比共享锁有更多限制
lock table person in share row exclusive mode;
排他锁:其他用户只能看,不能修改,不能加其他锁
lock table person in exclusive mode;
rollback 解锁
事务
原子|一致|隔离|持久
级别
NO_TRANSACTION 不支持事务
READ_UNCOMMITED 允许脏读、不可重复读、幻读
READ_COMMITED 允许不可重复读、幻读,不允许脏读
REPEATABLE 允许幻读,不允许脏读、不可重复读
SERIALIZABLE 脏读、不可重复读、幻读都不允许
执行事务,表加锁
conn.setAutoCommit(false);
conn.commit();
分布式事务
概念:多个提交阶段,提交到不同的物理DB中。
事务协调器,通过预提交的方式。同时提交到各个DB中;
将预提交消息持久化,等待预提交结果,全部成功后。
全部成功后,全部commit;
消息机制代替分布式事务
原理:A完成后,收到一个凭证。让B去完成下一步;
俩种模式
业务耦合
A完成后,插入一条消息到msg表;(同一事务)
将消息通过实时消息服务通知B
B完成后,删除消息;B失败,可以不停重试
业务解耦
A准备提交前,发消息给实时消息服务器;
消息服务器记录消息,但是不发送;
A提交成功;通知消息服务器发送消费;
A提交失败;回滚;通知消息服务取消发送;
B收到消息;执行B
重复发送消息问题;新增msg_apply表;发送完,插入;每次发送前查询;有就不发送;
SQL优化
分区
CRTTime
加索引
常用的where字段
order by 字段
避免全表扫描(索引无效)
or |in |like|
is null|!= | <>
无法转换的date类型 case as date
.不要在 where 子句中的“=”左边进行函数、算术运算或其他表达式运算
varchar/nvarchar 代替 char/nchar
.尽量避免大事务操作,提高系统并发能力。
避免向客户端返回大数据量
在新建临时表时,如果一次性插入数据量很大,那么可以
使用 select into 代替 create table,避免造成大量 log ,以提高速度
Spring
扩展类
<strong style="margin: 0px; padding: 0px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><span style="margin: 0px; padding: 0px; font-size: 15px;">InitialingBean</span></strong>
<span style="color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif;">afterPropertiesSet();bean属性加载完执行</span>
<strong style="margin: 0px; padding: 0px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><span style="margin: 0px; padding: 0px; font-size: 15px;">DisposableBean</span></strong>
<span style="color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif;">destory()bean结束后</span>
<strong style="margin: 0px; padding: 0px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><span style="margin: 0px; padding: 0px; font-size: 15px;">BeanNameAware</span></strong>
获取bean自身属性ID
<strong style="margin: 0px; padding: 0px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><span style="margin: 0px; padding: 0px; font-size: 15px;">ApplicationContextAware</span></strong>
获取Application上下文
<strong style="margin: 0px; padding: 0px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><span style="margin: 0px; padding: 0px; font-size: 15px;">BeanFactoryAware</span></strong>
获取beanFactory,getBean()获取任意bean
<strong style="margin: 0px; padding: 0px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px;">FactoryBean</strong>
getObject()获取一个Bean
getObjectType()获取一个bean的类型
<span style="color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif;">isSingleton()bean属性</span>
<strong style="margin: 0px; padding: 0px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><span style="margin: 0px; padding: 0px; font-size: 15px;">BeanPostProcessor</span></strong>
bean初始化前后
<strong style="margin: 0px; padding: 0px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px;">BeanFactoryPostProcessor</strong>
bean工厂初始化前后
<strong style="margin: 0px; padding: 0px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px;">InstantiationAwareBeanPostProcessor</strong>
bean实例化前后
AOP
子主题
子主题
子主题
Git
本地
git init / 当前目录创建一个仓库
git status /当前仓库的状态
git diff 文件 / 对比文件不通
git add 文件 / 将本地文件添加到暂存区,还没有提交哦
git commit -m "备注" / 提交。
是把暂存区的内容提交到分支,每次修改后都要 git add 放到暂存区,然后在提交
git log / 看日志
git reset --hard HEAD / 回到最新版本
git reset --hard id / id就是git log命令显示的commit id;只需要前几位就可以了
git reflog / 命令记录
git checkout -- 文件 / 就是把文件撤消修改到commit或add之后的版本;
git rm 文件/ 删除文件。需要commit才能有效,checkout可以返回
远程
<pre class="f5 js-zeroclipboard-target" style="box-sizing: border-box; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; font-stretch: normal; line-height: normal; color: rgb(51, 51, 51);"><span class="user-select-contain" style="box-sizing: border-box;">git remote add origin <span class="js-git-clone-help-text" style="box-sizing: border-box;">https://github.com/Elvis1988/0-boot-jar.git</span></span></pre>
<pre class="f5 js-zeroclipboard-target" style="box-sizing: border-box; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; font-stretch: normal; line-height: normal; color: rgb(51, 51, 51);"><span class="user-select-contain" style="box-sizing: border-box;">git push -u origin master/ 第一次推送,-u 会做个关联</span></pre>
git push origin master / 之后每次修改,本地commit之后,就可以推远程了
git clone http/;// / 克隆远程仓库的项目到本地,然后修改,add,commit之后,git push origin master到远程仓库
git svn clone http:// 获取svn管理的代码
git remote set-url origin git@192.168.6.70:res_dev_group/test.git # 变更远程地址
git remote -v # 变更有效
回退
下述命令file:单个文件,*.txt:某一类文件,.:所有文件
git checkout file|*.txt|. # 暂存区代码覆盖本地
git reset HEAD file | *.txt|. # 本地仓库最新回退到暂存区
git checkout HEAD file| *.txt| . # 本地仓库最新代码直接覆盖本地
git reset --hard HEAD^ # 本地代码直接回退 HEAD:最新版本。HEAD^:上一个版本。HEAD^^:上俩个版本。HEAD~10.10个版本前
git reset --hard commitId # 本地代码直接回退到某次提交上
git reset --hard origin/master # 本地代码回退到远程仓库代码
删除远程仓库代码
git rm # 删除
git commit -m "提交删除"
git push
强制覆盖本地代码
git fetch --all # 更新
git reset --hard origin/master # 回退到最新
git pull 更新
GitHub
参考git远程仓库的使用
开源项目,直接fork到自己的github;然后git clone到本地修改;可以提交到自己的github;
自己GitHub可以随意修改,可以pull request给原作者;同意后他就可以将你的修改同步到他的主干上;
分布式事务
连接
0 条评论
下一页