自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(46)
  • 资源 (5)
  • 收藏
  • 关注

原创 ExecutorCompletionService源码分析

之前有介绍过CompletionService用法的文章,这里直接拷过来,其实也是拷王宝令大佬的付费专栏里的介绍。 简介 CompletionService接口 用于批量执行异步任务,批量执行异步任务时更加优雅且更实用。 实现类是ExecutorCompletionService,提供了两个构造方法: 要传入一个线程池,还可以传入一个阻塞队列保存任务执行结果的 Fut...

2019-09-15 17:38:47 173

原创 Java Exchanger类

Java Exchanger类用于两个线程之间互相交换数据。当两方执行不对称的操作使,例如当一个线程向缓冲区写入数据,另一个线程从缓冲区中读取数据。这些线程可以使用Exchanger来汇合,并将满的缓冲区与空的缓冲区交换。当两个线程通过Exchanger交换对象时,这种交换就把这两个对象安全的发布给另一方。(Java并发编程实战) 为了方便理解,提供一个最简单的例子来展示他的基本用法。 st...

2019-06-23 15:39:15 144

转载 Java并发编程:volatile关键字解析

转载自:http://www.cnblogs.com/dolphin0520/p/3920373.html 这篇文章写的很好,防止迷路找不到原文,转载来了 volatile这个关键字可能很多朋友都听说过,或许也都用过。在Java 5之前,它是一个备受争议的关键字,因为在程序中使用它往往会导致出人意料的结果。在Java 5之后,volatile关键字才得以重获生机。   volatile关键字...

2019-06-23 09:41:19 150

原创 Runtime的addShutdownHook(Thread thtead)方法

最近看李号双老师的《深入拆解Tomcat&Jetty》专栏,里面提到了Catalina如何在使用Ctrl+c强制关闭Tomcat进程时,Tomcat如何优雅的停止并清理资源,使用到了想JVM注册一个“关闭钩子”。 具体的用法是使用Runtime.getRuntime().addShutdownHook(Thread hook)方法来实现。Runtime类的注...

2019-06-11 09:35:18 396

转载 项目中常用的19条SQL调优

转载自网络,有两条忘了记,所以就17条,侵删 1、用 EXPLAIN 查看 SQL 执行计划,找出优化点 2、SQL 语句中 in 包含的值不应过多 因为 MySQL 会用数组来保存 in 中字段数据,越多字段占用的内存越多,必要时(符合需求时)尽量在索引字段做 between and 来替代 in 3、SQL 中 select 后面必须指明要查询的字段,减少不必要的消耗,并且指...

2019-05-31 21:12:43 272

转载 SynchronousQueue功能分析

之前没用过 Executors.newCachedThreadPool() 线程池,被问及干啥的,为啥这么干,不会然后就被鄙视了。转载一篇同步队列的用法。 SynchronousQueue:同步Queue,属于线程安全的BlockingQueue的一种,此队列设计的理念类似于"单工模式",对于每个put/offer操作,必须等待一个take/poll操作,类似于我们的现实生...

2019-04-12 16:51:39 1056

原创 ThreadPoolExecutor使用注意事项

之前做过源码分析,链接如下: https://blog.csdn.net/u013759134/article/details/83659453 可知,ThreadPoolExecutor线程池对新到任务的处理流程简述如下(为了简单起见,暂只考虑Running状态): 1、查看当前工作线程数是否小于corePoolSize,如果是直接添加一个工作线程执行任务,不是转到2 2、添加任务到任务...

2019-04-12 11:34:13 661

转载 Java中强、软、弱、虚引用

本文转载自: http://www.cnblogs.com/xdouby/p/6701941.html java中有四种引用类型,分别表述如下: 1)强引用,任何时候都不会被垃圾回收器回收,如果内存不足,宁愿抛出OutOfMemoryError。 2)软引用,只有在内存将满的时候才会被垃圾回收器回收,如果还有可用内存,垃圾回收器不会回收。 3)弱引用,只要垃圾回收器运行,就肯定...

2019-04-10 21:43:45 113

转载 Java动态代理

Java提供动态代理的功能,spring AOP即利用动态代理的方式来实现面向切面编程,我们用一个很简单的例子来看一下Java本身的动态代理怎么用的。 可以看到,要实现对对象的动态代理,要调用Proxy.newProxyInstance()方法,改方法的入参需要传入被代理对象的类加载器、被代理对象的接口、一个InvocationHandler的实例。 代理对象执行被代理对象方法时,会调用Inv...

2019-04-10 11:11:59 68

原创 Semaphore源码分析

阅读本篇文章基础前提是对AQS有一定认识,如果看过前面的ReentranLock和CountDownLatch源码分析,看这篇文章就会轻松无比,且本文仅对最基本的acquire()方法和release()方法进行源码分析,其他版本获取、释放信号方法实现原理基本一致。 概述 Semaphore的概念类比操作系统的信号量,当然本身人家就叫semaphore。可以理解成Semaphore代表一组资源...

2019-04-02 09:30:12 227

原创 ConcurrentHashMap源码分析

概述 本文基于jdk1.8来对CurrentHashMap来做源码分析。 ConcurrentHashMap在jdk1.8中的源码实现和HashMap非常相似。这个容器的实现完美的展示了如何不用锁的情况下实现同步(当然里面还是用到了锁的),看代码真的叹为观止,收益匪浅。 在1.7前ConcurrentHashMap采用分段加锁的技术来实现,说白了就是初...

2019-03-22 10:23:34 247

原创 CountDownLatch源码分析

简介 CountDownLatch常用于多个线程同步,经典用法的套路就是主线程起多个子线程,主线程初始化一个对应数字的CountDownLatch,子线程调用countDown()方法表示自己执行完毕,主线程阻塞到await()方法,等待所有子线程都调用countDown()方法完成。达到主线程等待多个子线程任务执行完毕的目的。 CountDownLatch类加...

2019-03-13 17:07:59 124

原创 HashMap源码阅读

概述 开头注释说明: 实现Map接口所有定义功能,与HashTable功能基本一样,除了HashTable是同步的,且HashMap可以保存<null, null>。 HashMap使用bucket数组做Hash表,如果Hash散列的够好,get()、put()方法就可以在常量时间返回,效率高。但是对于使用Iterator迭代访问,就会消耗“桶数(...

2019-03-09 18:50:31 133

原创 ReentranLock源码分析

简介 ReentranLock实现了Lock接口,接口很简单,成员如下: ReentranLock内部主要是用AbstractQueuedSynchronizer来实现的,其中Sync就是实现AbstractQueuedSynchronizer抽象类,NofairSync和FairSync是 Sync的子类,分别对应非公平锁和公平锁的实现,实例化公平、非公平ReentranLock...

2019-03-09 18:21:50 220 1

原创 ScheduledThreadPoolExecutor源码阅读

1概述 ScheduledThreadPoolExecutor继承了ThreadPoolExecutor,同时还实现了ScheduledExecutorService接口,实现scheduleAtFixedRate、scheduleWithFixedDelay和schedule方法。我们平时使用ScheduledThreadPoolExecutor时最常用的方法就是scheduleA...

2019-02-20 16:37:58 483

原创 FutureTask源码分析

  1 前言介绍: Future接口: FutureTask实现了两个java接口,Runnable和Future。从代码注释可以看到Future接口被设计来执行异步任务,提供了检查计算是否完成(isDone()方法)、等待计算完成以及检索计算结果的方法(get()方法)。任务结果定义在实例化Future时传入。      1. get()方法: 可以从注释中看到接口设计get()方法的...

2019-02-18 15:17:55 278

原创 java对象赋值问题

        最近看FutureTask代码,里面有一个方法时遍历等待FutureTask任务执行完毕的链表,链表节点中保持等待任务完成的被阻塞的线程。这个遍历一下又让我懵了一下,再次记录一下java值传递、函数传参的问题。          我理解 WaitNode p = waiters 相当于把 p 指向waiters引用的对象,不管 p=null 还是 waiters=null ,...

2019-02-17 21:13:22 943

原创 ThreadPoolExecutor源码阅读

1. 概览 1.1 类架构 图1、类设计图 此图为Trust_FreeDom哥的图(https://www.cnblogs.com/trust-freedom/p/6681948.html),表达的...

2019-01-29 20:16:14 199

原创 linux单机安装测试kafka

首先要安装并启动zookeeper,特别注意的是zoo.cfg中有项配置 "dataDir=/tmp/zookeeper",一定要有对应目录,否则启动zookeeper时可能可以启动,但是kafka连不上zookeeper。 安装kafka,使用命令/bin/kafka-server-start.sh config/server.properties启动。 测试kafka...

2018-08-22 21:42:24 544

转载 链表快排

class Solution{ public: ListNode* sortList(ListNode* head) { if(head == NULL || head->next == NULL) return head; ListNode* begin = head, *end = NULL; Quicksort_list(begin, end); return be

2017-02-14 16:02:22 247

原创 kmp

void getnext(char *target ,int *next) { int len = strlen(target); next[0] = 0; for(int i=1,k=0;i<len;++i) { while(k>0 && target[i]!=target[k]) k = next[k-1]; if(target[i]==target[k]) k++

2016-10-05 08:57:43 191

原创 最长公共子序列

//最长公共子序列(记住公式即可答出) //公式: 0 ; i=0 || j=0 // C[i][j] = { C[i-1][j-1] ; str[i] == str[j] // max(C[i-1][j],C[i][j-1]; str[i] =/= str[j] int lengest(char* str1, char

2016-10-04 22:36:35 253

原创 leetcode Clone Graph

Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's undirected graph serialization: Nodes are labeled uniquely. We use # as a separator for each

2016-09-15 20:49:06 197

原创 leetcode Candy

There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at least on

2016-09-14 14:42:16 258

原创 leetcode Gas Station

There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to

2016-09-14 10:59:41 212

原创 leetcode Binary Tree Maximum Path Sum

Given a binary tree, find the maximum path sum. For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The

2016-09-09 09:46:00 228

原创 leetcode Best Time to Buy and Sell Stock

Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),

2016-09-06 11:03:48 242

原创 leetcode Triangle

Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [

2016-09-05 10:48:17 194

原创 leetcode Distinct Subsequences

Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (can be non

2016-09-04 20:12:16 256

原创 leetcode Flatten Binary Tree to Linked List

Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like: 1

2016-09-03 22:27:44 202

原创 leetcode Interleaving String

Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 = "aabcc", s2 = "dbbca", When s3 = "aadbbcbcac", return true. When s3 = "aadbbbaccc", r

2016-09-01 21:17:01 200

原创 leetcode Unique Binary Search Trees

Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \

2016-08-31 22:47:40 175

原创 leetcode Restore IP Addresses

Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example: Given "25525511135", return ["255.255.11.135", "255.255.111.35"]. (Order

2016-08-30 12:30:57 236

原创 LeetCode | Decode Ways

A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given an encoded message containing digits, determine the total nu

2016-08-29 10:39:35 303

原创 leetcode Maximal Rectangle

Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. For example, given the following matrix: 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1

2016-08-27 22:40:15 461

原创 LeetCode: Largest Rectangle in Histogram

Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. Above is a histogram where width o

2016-08-27 20:01:58 396

原创 leetcode Set Matrix Zeroes

Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click to show follow up. Follow up: Did you use extra space? A straight forward solution using O(m

2016-08-23 20:54:21 235

原创 leetcode Permutation Sequence

The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3): "123""132""213""231""3

2016-08-21 18:44:30 276

原创 线程特定数据

线程特定数据创建使用,简单例子,在别人小例子上修改

2016-07-28 22:09:13 276

原创 ubuntu安装搜狗输入法无法加到当前输入法原因

原因简单,要讲系统语言设置为汉语,logout,然后再登入就可以把搜狗输入法加到当前输入法了,系统语言再改回英文也可以用搜狗。

2016-06-15 22:37:07 582

hibernateDemo

hibernateDemo

2017-06-17

h264流,拆出来I帧与其余帧,并能重新组装,完整工程

可以提取h264流中的I帧和其他类型帧,并可以重新组装起来,还原出原来的h264流,使用了x264中代码,参考了网络上一位仁兄的代码

2015-11-03

bmp图片文件像素点RGB值读取完整工程

给定bmp格式图片文件,及所要读取像素的行列值,返回该像素点的RGB值

2015-10-13

数据库原理复习资料

数据库原理教程复习资料复习资料,内附多套练习题,做完这些你期末高分

2014-02-25

汇编语言复习资料

汇编语言期末考试复习资料,期末考试用的着。

2014-02-25

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除