- 博客(167)
- 收藏
- 关注
原创 Java线程的Interrupt方法与InterruptedException解析
线程阻塞状态与等待状态(当一个线程处于被阻塞或等待状态时,它暂时不活动,不允许任何代码且消耗最少的资源) 当一个线程试图获得一个内部的对象锁(而不是java.util.concurrent库中的锁),而该锁被其他线程持有,则该线程进入阻塞状态 当一个线程等待另一个线程通知调度器的一个条件时,它自己进入等待状态。在调用Object.wait方法或Thread.join方法,或者是等待java.util.concurrent库中的Lock或Condition时,就会出现这种情况。实..
2020-05-29 10:07:01 437
原创 Java的守护线程与非守护线程
Java分为两种线程:用户线程和守护线程所谓守护线程是指在程序运行的时候在后台提供一种通用服务的线程,比如垃圾回收线程就是一个很称职的守护者,并且这种线程并不属于程序中不可或缺的部分。因 此,当所有的非守护线程结束时,程序也就终止了,同时会杀死进程中的所有守护线程。反过来说,只要任何非守护线程还在运行,程序就不会终止。守护线程和用户线程的没啥本质的区别:唯一的不同之处就在于虚拟机的离开:如果用户线程已经全部退出运行了,只剩下守护线程存在了,虚拟机也就退出了。 因为没有了被守护者,守护线程也就没有工作
2020-05-29 09:31:48 191
原创 java中Unsafe类的“特殊”用法
最近在学习java.util.concurrent包的内容时,发现了一个java中很强大的工具类Unsafe,不仅提供了很强大的功能,如:操纵对象属性 操纵数组元素 线程挂起与恢复、CAS还发现了一些很“特殊”的用法。public native Object allocateInstance(Class<?> var1) throws InstantiationException;该方法可以通过Class对象构造一个对象实例。我们平时都是隐式(java反射)和显式地通过类
2020-05-27 19:19:43 314
原创 跳表(跳跃表)(SkipList)的java实现
跳表的详细数据结构解释见如下blog:跳跃表Skip List的原理和实现(Java)参照上述博文的实现如下:package com.foraixh.datastructure;import java.util.Random;/** * @author [email protected] * @date 2020/5/19 19:28 * @usage 跳跃表的简单实现 */public class SkipList<V> { /** * 跳跃表的头
2020-05-19 21:26:22 617
原创 如何正确使用redis分布式锁
什么是分布式锁分布式锁可以理解为:控制分布式系统有序的去对共享资源进行操作,通过互斥来保持一致性。实现原理 互斥性 安全性 避免死锁 保证加锁和解锁操作是原子性操作 使用redis实现分布式锁java代码如下:import org.springframework.data.redis.core.RedisTemplate;import org.springframework.data.redis.core.ValueOperations;impo
2020-05-13 23:09:04 246
原创 关于IDEA自动生成GET和SET方法时候的一些问题
一个java简单对象类有如下属性:使用alt+insert自动生成get和set方法时,生成的代码会是如下:此时,前后端交互时,前端post传过来的json值如果有isDictionaryValued:true时,springmvc自动生成这个java对象时,会去json中寻找dictionaryValued的值而不是isDictionaryValued的值。...
2020-03-19 15:26:11 1029
原创 240. 搜索二维矩阵 II
编写一个高效的算法来搜索mxn矩阵 matrix 中的一个目标值 target。该矩阵具有以下特性:每行的元素从左到右升序排列。每列的元素从上到下升序排列。示例:现有矩阵 matrix 如下:[ [1, 4, 7, 11, 15], [2, 5, 8, 12, 19], [3, 6, 9, 16, 22], [10, 13, 14, 17,...
2019-11-06 21:24:56 95
原创 221. 最大正方形
在一个由 0 和 1 组成的二维矩阵内,找到只包含 1 的最大正方形,并返回其面积。示例:输入:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0输出: 4class Solution { public int maximalSquare(char[][] matrix) { int m = matrix.length;...
2019-11-06 21:19:27 83
原创 Java将文件夹内所有文件及目录压缩为tar
打包 思路 准备输出流 FileOutputStream BufferedOutputStream TarOutputStream 准备输入流 FileInputStream BufferedInputStream 将文件打包为tar 代码 import org.apache.commons.compress...
2019-11-04 22:43:07 1962 1
原创 565. Array Nesting
A zero-indexed array A of length N contains all integers from 0 to N-1. Find and return the longest length of set S, where S[i] = {A[i], A[A[i]], A[A[A[i]]], ... } subjected to the rule below.Suppo...
2019-05-27 15:15:52 87
原创 项目开发记录--Realm Defense
最近时间比较多的情况下,抱着对Realm Defense游戏的热爱,也由于在群内(帝国守卫战 Realm Defense 725166239)“康子”的英雄觉醒进度自动计算表的灵感下,信息生出了写一个网页版的Realm Defense英雄觉醒进度更新表,当然也要有一些其他的功能,这些功能会单独写一篇博客以供记录。Realm Defense觉醒进度记录平台在今天,这个项目第一版已经跑起...
2019-05-16 17:35:13 2636
原创 记录一次服务器上安装mongodb的全过程
前言:之前自己的服务器由于是32位的,所以有很多限制,于是重新购买了一个64位的服务器,于是很多东西都需要重新安装了,其中就有mongodb。1,ssh进服务器,对照mongoDB 4.X - Ubuntu 完全安装手册安装好mongodb4.x。2,创建数据库管理员用户和创建新数据库的过程如下://创建数据库admin用户db.createUser({user:"Adm...
2019-05-15 22:22:43 766
原创 457. Circular Array Loop
You are given a circular array nums of positive and negative integers. If a number k at an index is positive, then move forward k steps. Conversely, if it's negative (-k), move backward k steps. Sinc...
2019-05-09 19:05:26 134
原创 442. Find All Duplicates in an Array
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear twice in this array.Could you do it without extra...
2019-05-06 20:47:49 93
原创 289. Game of Life
According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given a board with m by ...
2019-05-06 19:50:43 99
原创 215. Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.Example 1:Input: [3,2,1,5,6,4] and k = 2Output: 5Exa...
2019-04-30 20:59:30 86
原创 二叉查找树(BST)
二叉查找树(BST) 特殊的二叉树,又称为排序二叉树、二叉搜索树、二叉排序树。 二叉查找树实际上是数据域有序的二叉树,即对树上的每个结点,都满足其左子树上所有结点的数据域均小于或等于根结点的数据域,右子树上所有结点的数据域均大于根结点的数据域。如下图所示:二叉查找树通常包含查找、插入、建树和删除操作。二叉查找树的查找、插入和删除查找、插入和删除的代码就不一一...
2019-04-30 15:41:25 175
原创 212. Word Search II
Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those hori...
2019-04-29 21:20:34 108
原创 211. Add and Search Word - Data structure design
Design a data structure that supports the following two operations:void addWord(word)bool search(word)search(word) can search a literal word or a regular expression string containing only letters...
2019-04-29 17:16:43 95
原创 210. Course Schedule II
There are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pai...
2019-04-29 15:45:18 78
原创 208. Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods.Example:Trie trie = new Trie();trie.insert("apple");trie.search("apple"); // returns truetrie.search("app"); // returns fals...
2019-04-29 15:07:40 84
原创 207. Course Schedule
There are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pai...
2019-04-29 14:00:43 108
原创 200. Number of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assum...
2019-04-28 20:45:22 195
原创 188. Best Time to Buy and Sell Stock IV
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most k transactions.Note:You may not en...
2019-04-28 20:10:04 78
原创 180. Consecutive Numbers
Write a SQL query to find all numbers that appear at least three times consecutively.+----+-----+| Id | Num |+----+-----+| 1 | 1 || 2 | 1 || 3 | 1 || 4 | 2 || 5 | 1 || 6 | ...
2019-04-28 16:36:19 174
原创 178. Rank Scores
Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking number should be the next consecutive integer value....
2019-04-28 16:24:04 102
原创 177. Nth Highest Salary
Write a SQL query to get the nth highest salary from the Employee table.+----+--------+| Id | Salary |+----+--------+| 1 | 100 || 2 | 200 || 3 | 300 |+----+--------+For example, ...
2019-04-28 16:13:39 84
原创 176. Second Highest Salary
Write a SQL query to get the second highest salary from the Employee table.+----+--------+| Id | Salary |+----+--------+| 1 | 100 || 2 | 200 || 3 | 300 |+----+--------+For exampl...
2019-04-28 15:56:05 100
原创 175. Combine Two Tables
Table: Person+-------------+---------+| Column Name | Type |+-------------+---------+| PersonId | int || FirstName | varchar || LastName | varchar |+-------------+---------+Pe...
2019-04-28 15:37:38 84
原创 162. Find Peak Element
A peak element is an element that is greater than its neighbors.Given an input array nums, where nums[i] ≠ nums[i+1], find a peak element and return its index.The array may contain multiple peaks...
2019-04-28 15:03:06 65
原创 148. Sort List
Sort a linked list in O(n log n) time using constant space complexity.Example 1:Input: 4->2->1->3Output: 1->2->3->4Example 2:Input: -1->5->3->4->0Output: -1->...
2019-04-28 13:28:48 198
原创 140. Word Break II
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible...
2019-04-27 21:39:28 81
原创 139. Word Break
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.Note:The...
2019-04-27 20:16:09 86
原创 134. 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 its...
2019-04-24 20:39:45 95
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人