线程池与定时器 1.在什么情况下使用线程池? 1.单个任务处理的时间比较短 2.将需处理的任务的数量大 2. 使用线程池的好处: 1.减少在创建和销毁线程上所花的时间以及系统资源的开销 2.如不使用线程池,有可能造成系统创建大量线程而导致消耗完系统内存以及”过度切换”。 3. 使用线程池的风险 虽然线程池是构建多线程应用程序的强大机制,但使用它
各种格式之间转换 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
Mock常用方法 http://www.tuicool.com/articles/J7BFr2AMock 测试是单元测试的重要方法之一。Mockito是基于Java的Mock测试框架。 什么是 Mock 测试 Mock 测试就是在测试过程中,对于某些不容易构造(如 HttpServletRequest 必须在Servlet 容器中才能构造出来)或者不容易获取比较复杂的对象(如 JDBC 中的ResultS
rabbitmq组件断链重连机制 方案一: Rabbitmq在启动时,为rabbitmq设置一个status,在第一次建立连接的时候将其变为true,rabbitmq client在初始化时启动一个定时器,每隔一段时间开启一个线程,查询当前status的状态,如果status变为false,重新建立连接(包括connection、channel的连接)。方案二: Implement shutdown listener,如果rab
rabbitmq的鉴权 详细内容可以查看(http://www.rabbitmq.com/access-control.html)Rabbitmq有两种鉴权方式:一种是利用内置数据库鉴权。另一种是rabbitmq-auth-backend-http鉴权插件来实现后端鉴权。 Rabbitmq中,Authentication 和 authorisation是有区别的,authentication是“identifying w
rabbitmq基础 Exchange的三种typeDirect Exchange –通过binding key的完全匹配,binding key的名称与queue name的名称相同。 当P publish key是orange时,exchange会把它放到Q1。如果是black或者green那么就会到Q2。其余的Message都会被丢弃Fanout Exchange – 不通过bindingkey路由消息,excha
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 “
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
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
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
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
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
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
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
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
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
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
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
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
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 \