- 博客(30)
- 收藏
- 关注
原创 通过ReentrantLock学习AQS
一、排它锁,实现有公平锁和非公平锁两种。区别:公平锁吞吐量更小,能保持更高的有序性和减少饥饿性,但是不能保证完整的公平性。二、推荐使用方式:* <pre> {@code* class X {* private final ReentrantLock lock = new ReentrantLock();* // ...** public void m() {* lock.lock();...
2018-04-23 15:21:44 389
转载 springboot aop简单示例
AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术。AOP是Spring框架中的一个重要内容,它通过对既有程序定义一个切入点,然后在其前后切入不同的执行内容,比如常见的有:打开数据库连接/关闭数据库连接、打开事务/关闭事务、记录日志等。基于AOP不会破坏原来程序逻辑,因此它可以很好的对业务逻辑的各
2018-01-23 18:37:26 14155 4
原创 Redis:A服务器调用B服务器的redis
说明:1.在ubantu系统(ip:192.168.1.4)安装了redis,安装步骤很简单:a>到官网中下载最新稳定release版:redis-stable.tar.gzb>将文件放在/home/young/software/下解压,得到redis-4.0.6c>到redis-4.0.6下maked>启动:cd src./redis-server参考官网:h
2018-01-21 16:59:33 1210
原创 缓存初步学习
前前后后耗费1周左右时间,学习了XX的缓存机制。前提知识:1.UML画图:https://www.cnblogs.com/olvo/archive/2012/05/03/2481014.html2.Guava Cache:https://www.jianshu.com/p/64b0df87e51b最后附上UML图:
2018-01-18 17:12:09 351
原创 父子级项目打包及上传私服问题
http://blog.csdn.net/nocol123/article/details/73838089后记:如果有父子级的项目,比如父级为frame-parent,子级为frame-a和frame-b,并且frame-a依赖frame-b。直观处理步骤:1.将frame-b上传(deploy)到nexus私服;2.打包(package)frame-a。但是这时步骤2出错。
2018-01-10 23:10:36 2165
原创 FutureTask源码
前言: 看了Callable和Future合作用法,但只是知道FutureTask这个类并没有去看源码,然后昨天晚上躺在床上想要是FutureTask继承Future以及将Callable作为其属性进而更好地管理这两者的组合,结果今天一看,果然。。。好了,言归正传,开始学习FutureTask。1.首先看其中一个构造函数。public FutureTask(
2018-01-06 21:47:21 290
原创 nginx部署
openssl-1.0.2m.tar.gzzlib-1.2.11.tar.gzpcre-8.41.tar.gznginx-1.12.2.tar.gz准备工作:所有工作的/home/admin/nginx/目录下执行将上面四个文件放在/home/admin/nginx/下1.安装gcc,linux服务都有,跳过2.安装p
2017-11-10 18:01:35 283
原创 AbstractQueuedSynchronizer(AQS)
最后总结:AQS主要管理共用某资源的thread,这些thread用Node包装,然后用AQS的Node head、tail来管理,这些thread何时可以获取(tryacquire )锁,都由AQS的管理机制来决定。主要参考资料:源码以及http://www.iigrowing.cn/java_duo_xian_cheng_zhong_gong_ping_suo_1.html
2017-11-05 22:33:18 267
原创 AtomicIntegerFieldUpdater
主要跟上一篇的AtomicInteger一起对比,AtomicInteger设计的目的是对某个Ingeter的线程安全操作,AtomicIntegerFieldUpdater设计的目标是对某class中的某Integer(或int)属性进行并发操作,并保护操作的原子性和线程的安全性。AtomicIntegerFieldUpdater本身是abstract的,使用实例:
2017-10-17 23:07:15 277
原创 邮件正文发送图片兼容性问题
正文发送图片,从开始到完善,总共经历了2种方法。第一种:.ftl模板: imgList as imgList>imgsrc="data:image/png;base64,${imgList.img}">java中:1>利用JFreeMarker获取到jpeg图片;2>将.jpeg转为Base64的Str
2017-10-13 18:01:21 769
原创 AtomicInteger
主要属性private volatile intvalue;由volatile修饰,volatile关键字参考:http://www.cnblogs.com/dolphin0520/p/3920373.html 主要方法/*** Atomically sets the value to th
2017-10-11 09:12:33 289
原创 LeetCode-213. House Robber II
Note: This is an extension of House Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time
2016-04-25 15:21:33 415
原创 Leetcode-198. House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house
2016-04-25 13:40:11 379
原创 LeetCode-337. House Robber III
这道题主要参照http://www.2cto.com/kf/201603/493582.html代码如下:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(i
2016-04-25 11:22:41 462
原创 LeetCode-338. Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:For num = 5
2016-04-24 22:53:31 365
原创 LeetCode-342. Power of Four
这道题,主要考察对二进制的理解吧。。我们知道类似1000,1 0000,10 0000,...是 2 的幂次方,那么怎么样才能是 4 的幂次方呢?就是要求后面的 0 的个数为偶数!class Solution {public: bool isPowerOfFour(int num) { int num1 = num - 1; if((num&num1)
2016-04-20 20:11:41 418
原创 LeetCode-343. Integer Break
整个思路参考 博客: http://blog.csdn.net/liyuanbhu/article/details/51198124本来自己试着写了一段:class Solution {public: int integerBreak(int n) { if(n == 2) return 1; if(n == 3) return 2;
2016-04-20 19:34:14 380
原创 LeetCode-linked-list-cycle-ii
题目:如果一个链表循环,返回第一个进入循环的点,否则返回NULL。class Solution {public: ListNode *detectCycle(ListNode *head) { if(head==NULL || head->next==NULL) return NULL; ListNode* pslow
2016-03-21 10:23:02 353
原创 LeetCode-reorder-list
主要参考 hackersun007的修行之路的文章http://blog.csdn.net/doc_sgl/article/details/14110209
2016-03-19 16:21:23 332
原创 LeetCode-Binary Tree Postorder Traversal
题目:很正常的二叉树后序遍历。用递归调用非常快速。class Solution {public: std::vector v; vector postorderTraversal(TreeNode *root) { poserorder(root); return v; } void poserorder(TreeNode *
2016-03-19 14:06:03 318
原创 LeetCode-max-points-on-a-line
这个问题是求在一个平面上,共线最多的点的个数。本文参考了@一个健忘症患者的记忆备份 的博客,地址为http://blog.csdn.net/liushu1231/article/details/19839645技能get:1.map的使用2.iterator的使用。用iterator对map对象的find,insert的操作都很有用。
2016-03-18 20:27:02 284
原创 LeetCode- Evaluate Reverse Polish Notation
题目:Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.数学表达式的 逆式波兰记法。答案:
2016-03-17 21:28:56 378
原创 LeetCode minDepth of 2 bin tree
111. Minimum Depth of Binary Tree题目:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf n
2016-03-17 19:21:25 351
原创 python数据可视化--散点图以及分类
在绘制《机器学习实战》第六章的简单二分类数据时,想用散点图来绘制,但是始终没有结果,还好,花了半天的时间搞清楚了大致流程。特作笔记如下。先看效果图:注意点一:在书中P95页,得到dataArr,和labelArr两个数据,首先要对它们进行预处理:拿到的数据是普通矩阵形式的,而scatter函数的参数是array类型,所以要进行格式转换:dataArr_c=numpy.arr
2015-12-26 17:27:20 6522
原创 LeetCode-Contains Duplicate III
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i an
2015-10-11 11:39:41 388
原创 LeetCode-Contains Duplicate II
Given an array of integers and an integer k, find out whether there there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k.
2015-10-10 19:09:42 322
原创 LeetCode-Contains DuplicateI
class Solution {public: bool containsDuplicate(vector& nums) { sort(nums.begin(),nums.end()); for (int i = 1; i < nums.size(); ++i) { if (nums[i] == nums[i - 1]) { return 1; } }
2015-09-25 19:52:06 421
原创 LeetCode-Move Zeroes
class Solution {public: void moveZeroes(vector& nums) { int pos = 0; // 将非0数字都尽可能向前排 for(int i = 0; i < nums.size(); i++){ if(nums[i] != 0){
2015-09-25 18:36:14 322
原创 leetcode-First Bad Version
bool isBadVersion(int version);class Solution {public:int firstBadVersion(int n) {if (n return -1;}int start = 1, end = n;int mid;while (start + 1 mid = start + (end - start) /
2015-09-25 18:32:18 364
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人