0%

  • start() && run() 源码
  • 区别
  • Demo及Demo遇到的问题 (Method Reference)

Thread

Source Code

Thread start()

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
/**
* Causes this thread to begin execution; the Java Virtual Machine
* calls the <code>run</code> method of this thread.
* <p>
* The result is that two threads are running concurrently: the
* current thread (which returns from the call to the
* <code>start</code> method) and the other thread (which executes its
* <code>run</code> method).
* <p>
* It is never legal to start a thread more than once.
* In particular, a thread may not be restarted once it has completed
* execution.
*
* @exception IllegalThreadStateException if the thread was already
* started.
* @see #run()
* @see #stop()
*/
public synchronized void start() {
/**
* This method is not invoked for the main method thread or "system"
* group threads created/set up by the VM. Any new functionality added
* to this method in the future may have to also be added to the VM.
*
* A zero status value corresponds to state "NEW".
*/
if (threadStatus != 0)
throw new IllegalThreadStateException();

/* Notify the group that this thread is about to be started
* so that it can be added to the group's list of threads
* and the group's unstarted count can be decremented. */
group.add(this);

boolean started = false;
try {
start0();
started = true;
} finally {
try {
if (!started) {
group.threadStartFailed(this);
}
} catch (Throwable ignore) {
/* do nothing. If start0 threw a Throwable then
it will be passed up the call stack */
}
}
}

Thread run()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* If this thread was constructed using a separate
* <code>Runnable</code> run object, then that
* <code>Runnable</code> object's <code>run</code> method is called;
* otherwise, this method does nothing and returns.
* <p>
* Subclasses of <code>Thread</code> should override this method.
*
* @see #start()
* @see #stop()
* @see #Thread(ThreadGroup, Runnable, String)
*/
@Override
public void run() {
if (target != null) {
target.run();
}
}

Diff

start() 方法是真正的启动方法,是并行调用的

run()是Thread中的一个方法,是串行调用的

阅读全文 »

MyBatis原理

TODO

主要接口

SqlSessionFactory

  • Spring框架中<<FactoryBean<SqlSessionFactory>>利用FactoryBean功能构建出SqlSessionFactoryBean。
  • 通过SqlSessionFactoryBuilder构建出SqlSessionFactory(自带仅一个DefaultSqlSessionFactory实现类)
  • 之后可以通过SqlSessionFactory构造出SqlSession

SqlSession

  • 访问MyBatis门户
  • 自带仅一个DefaultSqlSession实现类

Configuration & Mapper

Configuration

  • MyBatis本身配置信息
  • 接口配置信息

Mapper

Executor

Transaction

Mapper

MapperProxy

selectList

doQuery

来源

https://www.icourse163.org/learn/XMU-1462056168#/learn/content

Spring缓存

为什么需要缓存

  • 减轻服务器压力
客户端缓存 CDN对象存储
接入服务器 NGIX缓存
应用服务器Tomcat Mybatis && Hibernate缓存 分布式缓存/Redis

Spring Cache

  • Spring Cache 是Spring 提供的一整套的缓存解决方案(JSR- 107),
  • 提供一整套的接口和代码规范、配置、注解等,用于整合各种缓 存方案,如Redis、Caffeine、Guava Cache、Ehcache

不推荐原因

  • 无法测试:无法进行切片测试
  • 不支持复杂结构,只能进行简单对象查询存储
阅读全文 »

MySQL存储结构

InnoDB存储

表->段->区->页->行

在数据库中,不论读哪一行数据,还是读多行数据,都是将这些行所在的页进行加载。也就是存储空间的基本单位就是页。

一个页就是一颗B+树的节点,数据库I/O操作的最小单位是页,与数据库相关的内容都会存储在页的结构里。

1629471915

阅读全文 »

Linux如何设置忘记网络

问题

PI (Debian OS)同时连接2.4G与5G网络,5G不稳定需删除SSID,记录删除方法

方法

  • 删除SSID方法

    1
    2
    3
    4
    5
    6
    # 查看当前记录的SSID
    nmcli -t -f TYPE,UUID,NAME con
    # 查询结果
    802-11-wireless:12345678-31d1-51e7-a60e-3a52e52b4495:YourWifiName
    # 删除需要处理的UUID
    sudo nmcli c delete 12345678-31d1-51e7-a60e-3a52e52b4495
阅读全文 »

Singleton Pattern

Conceptual

  • 保证一个类只有一个实例

  • 为该实例提供一个全局访问节点

无论何时调用该方法,它总是会返回相同的对象

Pros & Cons

Pros

  • 你可以保证一个类只有一个实例,提供了一个指向该实例的全局访问节点
  • 仅在首次请求单例对象时对其进行初始化
阅读全文 »

./AbstractApplicationContext

1
2
3
4
public static void main(String[] args) {
// 执行SpringAppllication的静态run方法
SpringApplication.run(SampleTomcatApplication.class, args);
}

Version:

  • spring-context-6.0.0-SNAPSHOT.jar
  • spring-beans-5.3.15.jar
  • spring-aop-6.0.0-SNAPSHOT.jar
  • spring-core-6.0.0-SNAPSHOT.jar
阅读全文 »

RPC

RPC-远程过程调用,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议。

定义

RPC(Remote Procedure Call)—远程过程调用,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议。也就是说两台服务器A,B,一个应用部署在A服务器上,想要调用B服务器上应用提供的方法,由于不在一个内存空间,不能直接调用,需要通过网络来表达调用的语义和传达调用的数据。

RPC协议假定某些传输协议的存在,如TCP或UDP,为通信程序之间携带信息数据。在OSI网络通信模型中,RPC跨越了传输层和应用层。RPC使得开发包括网络分布式多程序在内的应用程序更加容易。现在业界有很多开源的优秀 RPC 框架,例如 Spring Cloud、Dubbo、Thrift 等。

阅读全文 »