0%

案例出自 马士兵MAC课程

案例代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public class Test01 {
public static void main(String[] args) {
Thread t1 = new Thread(() -> {
System.out.println("t1 start");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("t1 end");
}, "thread-0");
t1.start();

Thread t2 = new Thread(() -> {
synchronized (t1) {
System.out.println("t2 start");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("t1 isAlive: " + t1.isAlive());
}
}, "thread-1");
t2.start();
}
}
阅读全文 »

案例出自 马士兵MAC课程

案例代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
public class OSRDemo {
static long counter;

public static void main(String[] args) throws Exception {
System.out.println("main start");
startBusinessThread();
startProblemThread();
// 等待线程启动执行
Thread.sleep(500);
// 执行GC
System.gc();
System.out.println("main end");
}

private static void startProblemThread() {
new Thread(() -> {
System.out.println("Problem start");
for (int i = 0; i < 1000000; i++) {
for (int j = 0; j < 100000; j++) {
counter += i % 33;
counter += i % 333;
}
}
}).start();
}

private static void startBusinessThread() {
new Thread(() -> {
System.out.println(Thread.currentThread().getName() + " start");
while (true) {
System.out.println("执行业务一");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}, "thread-01").start();
}
}
阅读全文 »

Leetcode-912.排序数组

给你一个整数数组 nums,请你将该数组升序排列。

递归版本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class Solution {
public int[] sortArray(int[] nums) {
if (nums.length < 2) {
return nums;
}
process(nums, 0, nums.length - 1);
return nums;
}

public void process(int[] nums, int left, int right) {
if (left == right) {
return;
}
int mid = left + ((right - left) >> 1);
process(nums, left, mid);
process(nums, mid + 1, right);
merge(nums, left, right, mid);
}

public void merge(int[] nums, int left, int right, int mid) {
int[] help = new int[right - left + 1];
int i = 0;
int leftPoint = left;
int rightPoint = mid + 1;
while (leftPoint <= mid && rightPoint <= right) {
help[i++] = nums[leftPoint] < nums[rightPoint] ? nums[leftPoint++] : nums[rightPoint++];
}
while (leftPoint <= mid) {
help[i++] = nums[leftPoint++];
}
while (rightPoint <= right){
help[i++] = nums[rightPoint++];
}
for (int j = 0; j < help.length; j++) {
nums[left + j] = help[j];
}
}
}
阅读全文 »

本文学习自马士兵MAC课程-源码五班

目的

通过 Debug 探究以下问题:

  1. AbstractApplicationContextrefresh() 中,完成对 bean 的实例化方法 finishBeanFactoryInitialization(beanFactory) 是否会实例化 UserFactoryBean 和 User 的对象
  2. context.getBean(“&userFactoryBean”)context.getBean(“userFactoryBean”) 会返回不同对象的逻辑是什么?
阅读全文 »

本文灵感源自马士兵MAC课程-源码五班

案例代码

实体类 Boss 和 Bar

1
2
3
4
5
6
7
package com.eitan.condition.entity;

import org.springframework.stereotype.Component;

@Component
public class Boss {
}
1
2
3
4
package com.eitan.condition.entity;

public class Bar {
}

可以看到,Boss 上是添加了 @Component 注解的,Spring 通过包扫描可以将其添加进容器

阅读全文 »

本文学习自马士兵MAC课程-源码五班

需求

自定义一个 Address 类,包含三个字段 province、city、town,给 Address 用字符串进行赋值,字符串用下划线分割 province、city、town,最终能使 BeanFactory 成功解析。

1
2
3
4
5
6
7
8
9
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="customer" class="com.eitan.editor.entity.Customer">
<property name="name" value="zs"></property>
<property name="address" value="福建省_福州市_闽侯县"></property>
</bean>
</beans>
阅读全文 »

题目

在一个 n * m 的二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个高效的函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。

示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
现有矩阵 matrix 如下:

[
[1, 4, 7, 11, 15],
[2, 5, 8, 12, 19],
[3, 6, 9, 16, 22],
[10, 13, 14, 17, 24],
[18, 21, 23, 26, 30]
]
给定 target = 5,返回 true
给定 target = 20,返回 false

限制:
0 <= n <= 1000
0 <= m <= 1000

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

阅读全文 »