今日学习内容
白天继续复习,准备面试.
回忆了一下昨天答得不好的部分:
ThreadLocal跨线程问题:
子线程继承父线程的时候可以通过InheritableThreadLocal来实现一个类似快照的复制,tips:是复制,而不是实时的通信.
多线程的手撕(拉的最大)
总结到了算法笔记里面,基本实现方式就是通过synchronized字段或者ReentrantLock来实现,然后在主线程里面定义几个线程.
项目拷打的部分,TecHub的实现有点忘记了,导致有点磕巴.
Apache Tika进行文档解析出来的格式是什么样的?
首先会分成元数据和内容两个部分.元数据里面存放的就是文档的”身份标签”,而内容部分就是解析出来的格式相同的正文,一般存储为xml的格式.
举个例子如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <html xmlns="http://www.w3.org/1999/xhtml"> <body> <h1>这是主标题</h1> <p>这是一个普通的段落。</p> <table> <tr> <td>姓名</td> <td>张三</td> </tr> <tr> <td>年龄</td> <td>25</td> </tr> </table> <p>段落结束。</p> </body> </html>
|
ES向量化搜索底层用的是什么方法?
近似最近邻搜索 - HNSW(ES默认且最常用)
MVCC的字段
MinIO返回给前端的url是否加密
面完了…感觉被大佬创飞了…🥲
并发又拉了,真得狠狠沉淀并发了.
线程池实现1到100求和:
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
| import java.util.ArrayList; import java.util.List; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger;
public class ThreadPoolSum {
public static void main(String[] args) throws Exception { System.out.println("方法1结果:" + sumWithCallable());
System.out.println("方法2结果:" + sumWithCompletableFuture());
System.out.println("方法3结果:" + sumWithDivideAndConquer()); }
public static int sumWithCallable() throws Exception { ExecutorService executor = Executors.newFixedThreadPool(4); int chunkSize = 10; int taskCount = 10;
List<Future<Integer>> futures = new ArrayList<>();
for (int i = 0; i < taskCount; i++) { final int start = i * chunkSize + 1; final int end = (i + 1) * chunkSize;
Callable<Integer> task = () -> { int sum = 0; for (int j = start; j <= end; j++) { sum += j; } return sum; };
futures.add(executor.submit(task)); }
int totalSum = 0; for (Future<Integer> future : futures) { totalSum += future.get(); }
executor.shutdown(); return totalSum; }
public static int sumWithCompletableFuture() throws Exception { ExecutorService executor = Executors.newFixedThreadPool(4);
List<CompletableFuture<Integer>> futures = new ArrayList<>();
for (int i = 0; i < 10; i++) { final int start = i * 10 + 1; final int end = (i + 1) * 10;
CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> { int sum = 0; for (int j = start; j <= end; j++) { sum += j; } return sum; }, executor);
futures.add(future); }
CompletableFuture<Void> allFutures = CompletableFuture.allOf( futures.toArray(new CompletableFuture[0]) );
CompletableFuture<Integer> totalFuture = allFutures.thenApply(v -> futures.stream() .map(CompletableFuture::join) .reduce(0, Integer::sum) );
int result = totalFuture.get(); executor.shutdown(); return result; }
public static int sumWithDivideAndConquer() throws Exception { ExecutorService executor = Executors.newFixedThreadPool(4); AtomicInteger totalSum = new AtomicInteger(0);
int tasks = 5; int numbersPerTask = 20;
CountDownLatch latch = new CountDownLatch(tasks);
for (int i = 0; i < tasks; i++) { final int start = i * numbersPerTask + 1; final int end = (i == tasks - 1) ? 100 : (i + 1) * numbersPerTask;
executor.execute(() -> { try { int partialSum = 0; for (int j = start; j <= end; j++) { partialSum += j; } totalSum.addAndGet(partialSum); } finally { latch.countDown(); } }); }
latch.await(); executor.shutdown(); return totalSum.get(); } }
|
3DGS
力扣每日一题
今天的每日一题是一个简单题,但是简单是因为他的数据范围只有0到50,稍微增加一些数据就会是困难题目.
先存一个档,我使用滑窗加上单调队列实现,但是滑窗内有遍历,灵神的题解用的对顶堆,等过一阵再研究这个题目.todo.
算法力扣Hot100
85/100
SQL50题
29/50
Java复习进度
- Java进阶之路
- Java SE🔥
56/56
- Java集合框架🔥
30/30
- Java并发编程🔥
71/71
- JVM🔥
54/54
- MySQL🔥
83/83
- Redis🔥
57/57
- Spring🔥
6/41
- 操作系统
34/34
- 计算机网络🔥
8/62
- MyBatis
24/24
- Elasticsearch
记录了一篇笔记.
- RocketMQ
9/24
- 分布式
12/12
- 微服务
4/32
- 设计模式
5/5
- Linux
3/3
- 场景设计
1
MYDB
10/10
项目-TecHub
项目-RAG
RAG题目
31/31
架构设计
25/25
用户管理
11/11
文件上传解析
19/19
知识库检索
13/13
聊天助手
13/13
生活篇
晚上健身