- 博客(60)
- 收藏
- 关注
原创 线程池与定时器
1.在什么情况下使用线程池? 1.单个任务处理的时间比较短 2.将需处理的任务的数量大 2. 使用线程池的好处: 1.减少在创建和销毁线程上所花的时间以及系统资源的开销 2.如不使用线程池,有可能造成系统创建大量线程而导致消耗完系统内存以及”过度切换”。 3. 使用线程池的风险 虽然线程池是构建多线程应用程序的强大机制,但使用它
2016-10-16 20:52:42
2145
原创 各种格式之间转换
String转json String jstr=”{‘json’:’jsonvalue’,’bool’:true,’int’:1,’double’:’20.5’}”; JSONObject json=JSONObject.fromObject(jstr); boolean bool=json.getBoolean(“bool”); int i=json.getInt(“int”); dou
2016-10-16 17:34:03
394
原创 Mock常用方法
http://www.tuicool.com/articles/J7BFr2AMock 测试是单元测试的重要方法之一。Mockito是基于Java的Mock测试框架。 什么是 Mock 测试 Mock 测试就是在测试过程中,对于某些不容易构造(如 HttpServletRequest 必须在Servlet 容器中才能构造出来)或者不容易获取比较复杂的对象(如 JDBC 中的ResultS
2016-10-16 17:19:51
11403
原创 rabbitmq组件断链重连机制
方案一: Rabbitmq在启动时,为rabbitmq设置一个status,在第一次建立连接的时候将其变为true,rabbitmq client在初始化时启动一个定时器,每隔一段时间开启一个线程,查询当前status的状态,如果status变为false,重新建立连接(包括connection、channel的连接)。方案二: Implement shutdown listener,如果rab
2016-10-16 15:43:28
17075
原创 rabbitmq的鉴权
详细内容可以查看(http://www.rabbitmq.com/access-control.html)Rabbitmq有两种鉴权方式:一种是利用内置数据库鉴权。另一种是rabbitmq-auth-backend-http鉴权插件来实现后端鉴权。 Rabbitmq中,Authentication 和 authorisation是有区别的,authentication是“identifying w
2016-10-16 15:36:57
3057
原创 rabbitmq基础
Exchange的三种typeDirect Exchange –通过binding key的完全匹配,binding key的名称与queue name的名称相同。 当P publish key是orange时,exchange会把它放到Q1。如果是black或者green那么就会到Q2。其余的Message都会被丢弃Fanout Exchange – 不通过bindingkey路由消息,excha
2016-10-16 15:07:23
367
原创 LeetCode_3 Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is 3. For “
2015-08-03 15:48:24
496
原创 LeetCode_234 Palindrome Linked List
Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time and O(1) space?public boolean isPalindrome(ListNode head) { if(head == null || h
2015-08-03 14:10:29
309
原创 LeetCode_206 Reverse Linked List
Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursively. Could you implement both?pre始终是首元结点的值,每次对pnext重新赋值 递归 public ListNode reverseList(ListNode
2015-08-03 11:34:08
354
原创 LeetCode_237 Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with valu
2015-07-31 11:31:49
335
原创 Leetcode_226 Invert Binary Tree
Invert a binary tree. 4/ \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia: This problem was inspired by this original tweet by Max Howell: Go
2015-07-30 18:22:24
304
原创 LeetCode_199 Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example: Given the following binary tree, 1
2015-07-30 18:19:01
326
原创 LeetCode_145 Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [3,2,1]. private void resPreorder(TreeNode
2015-07-30 18:16:19
321
原创 LeetCode_144 Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,2,3].List<Integer> result = new ArrayList
2015-07-30 18:13:32
378
原创 LeetCode_124 Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example: Given the below binary tree, 1 / \ 2 3Return 6.如果这个作为root,那么最长路应该就是F(left) + F(ri
2015-07-30 11:33:51
331
原创 LeetCode_222 Count Complete Tree Nodes
Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from Wikipedia: In a complete binary tree every level, except possibly the last, is completely fill
2015-07-29 17:36:02
363
原创 LeetCode_230 Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note: You may assume k is always valid, 1 ≤ k ≤ BST’s total elements. Follow up: What i
2015-07-29 16:33:55
331
原创 LeetCode_129 Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the total sum of al
2015-07-29 16:09:46
383
原创 LeetCode_235 Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two
2015-07-29 15:48:35
300
原创 LeetCode_114 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 \ 2 \
2015-07-29 11:20:40
282
原创 LeetCode_113 Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum. For example: Given the below binary tree and sum = 22, 5
2015-07-28 21:52:10
208
原创 LeetCode_112 Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree and
2015-07-28 20:56:25
300
原创 LeetCode_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 node.public int minDepth(TreeNode root) {
2015-07-28 17:48:03
265
原创 LeetCode_110 Balanced Binary Tree
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diff
2015-07-28 17:12:47
339
原创 LeetCode_108 Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.高度平衡是指左右子树的高度最大相差1,二分检索树是,根节点的左子树的所有节点值都小于等于根节点,右子树的所有节点值都大于等于根节点,左右子树也是二分搜索树。 public TreeNode sort
2015-07-28 11:40:03
250
原创 LeetCode_107 Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).For example: Given binary tree {3,9,20,#,#,15,7},
2015-07-28 10:28:11
287
原创 LeetCode_106 Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.public TreeNode buildTree(int[] inorder, int[] postorder) { int size = inorder.length; if(size ==0) return
2015-07-28 10:03:50
283
原创 LeetCode_105 Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree. public TreeNode buildTree(int[] preorder, int[] inorder) { int size = inorder.length; if(size ==
2015-07-27 18:07:17
300
原创 LeetCode_103 Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary
2015-07-15 21:28:12
259
原创 LeetCode_104 Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.可以采用递归,DFS public int maxDepth(T
2015-07-15 17:42:40
275
原创 LeetCode_102 Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level). For example: Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9
2015-07-15 16:56:26
278
原创 LeetCode_101 Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 B
2015-07-15 14:43:55
352
原创 Leetcode_100 Same Tree
Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. public bo
2015-07-15 14:03:15
260
原创 Leetcode_98 Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node’s key.
2015-07-15 10:52:55
272
原创 Leetcode_95 Unique Binary Search Trees II
Given n, generate all structurally unique BST’s (binary search trees) that store values 1…n. For example, Given n = 3, your program should return all 5 unique BST’s shown below. 1 3
2015-07-14 17:05:42
261
原创 LeetCode_96 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
2015-07-14 15:30:01
268
原创 Leetcode_94 Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes’ values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,3,2]. Note: Recursive
2015-07-14 14:28:42
353
原创 深入JVM(之一)--Java内存区域与内存溢出异常
Java与C++之间有一睹由内存动态分配和垃圾收集技术所围成的“高墙”,墙外的人想进去,墙内的人想出去。运行时数据区域Java虚拟机在执行Java程序的过程中会把它所管理的内存划分为若干个不同的数据区域,这些数据区域各有用途,以及创建和销毁的时间,有的区域会随着虚拟机进程的启动而存在,有的区域则依赖用户线程的启动和结束而建立和销毁。Java虚拟机所管理的内存将会包括以下几个运行时数据区域程序计数器
2015-07-08 22:14:46
374
原创 Struts(之一)--基本介绍
MVC思想MVC并不是Java语言所特有的设计思想,它是所有面向对象程序设计语言都应该遵守的思想。 MVC思想将一个应用分成三个基本部分:Model(模型)、View(视图)和Controller(控制器)。这三部分以最少的耦合协同工作,从而提高应用的可扩展性和可维护性。 MVC思想类似于观察者模式,但又有区别:观察者模式下观察者和被观察者可以是两个互相等的对象,但MVC被观察者往往只是单纯的数
2015-07-07 13:24:34
350
原创 Hibernate(之一)--基本介绍
Hibernate是轻量级Java EE应用的持久层的解决方案,Hibernate不仅管理Java类到数据库表的映射(包括Java数据类型到SQL数据类型的映射),还提供数据查询和获取数据的方法,可以大幅度缩短处理数据持久化时间。 Hibernate较之另一个持久层框架MyBatis,Hibernate更具有面向对象的特征:受Hibernate的影响,JavaEE规范抛弃了传统的Entity EJ
2015-07-06 21:01:00
513
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人