Skip to content
Permalink
Browse files

feat: 0531 update note.

  • Loading branch information...
alterhu2020 committed Jun 1, 2019
1 parent efcbb39 commit 9ce3cc8a7976e243960e36f1e273cde5dec353d0
@@ -143,7 +143,7 @@ module.exports = {
lastUpdated: 'Last update',
nav: [
{
text: 'My Blog',
text: 'BLOG',
link: '/blog/'
},
{
@@ -12,6 +12,8 @@ module.exports ={
title: '2019年',
collapsable: false,
children: [
'2019/05-31-what',
'2019/05-29-what',
'2019/05-26-what',
'2019/05-25-what',
'2019/05-24-what',
@@ -9,7 +9,9 @@ title: 5月26日整理
- 检查mysql的时区:

```bash
show variables like "%time_zone%";
```
+------------------+--------+
| Variable_name | Value |
@@ -0,0 +1,87 @@
---
title: 5月29日整理
---

## fiddler抓包手机app及其微信小程序请求

参考文档: https://www.jianshu.com/p/b0344958186f

需要注意两点:
1. fiddler安装在windows上,而被抓包的手机可以是任意手机,不管是Android 的还是苹果的。
2. 苹果的注意以下几步:
2.1 设置WiFi手动代理;
2.2 下载fiddler证书;
2.3 描述文件证书验证,通用 - 描述文件与设备管理 - DO_NOT_TRUEST_FIDDLERROOT;
2.4 证书设置信任, 这一部分也是重要的一步,不少人就是因为没设置为受信任的证书而失败的
设置-通用-关于本机-证书信任设置;

如下为一个成功抓包的请求:
```
GET https://geque.yzzisha.com/guifan/api/index.php?m=home&c=User&a=getIndex1&page=1&pageSize=20&class_id=132&keyword= HTTP/1.1
Host: geque.yzzisha.com
Content-Type: application/json
Connection: keep-alive
Accept: */*
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.4(0x17000428) NetType/WIFI Language/zh_CN
Referer: https://servicewechat.com/wx930cfdbaa071134a/12/page-frame.html
Accept-Language: zh-cn
Accept-Encoding: br, gzip, deflate
```

## Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 2018-04-30 of type java.tim

> 原因日期格式的时间不能转化为LocalDateTime
可采用如下方法解决:

```java
public static LocalDateTime parseDate(String dateStr) {
DateTimeFormatter baseDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder().append(baseDateTimeFormatter)
.parseDefaulting(ChronoField.HOUR_OF_DAY, 0)
.parseDefaulting(ChronoField.MINUTE_OF_HOUR, 0)
.parseDefaulting(ChronoField.SECOND_OF_MINUTE, 0)
.toFormatter();
return LocalDateTime.parse(dateStr, dateTimeFormatter);
}
```

## mysql快速重命名数据库名称

> 参考文档: [How to Rename a Database in MySQL](https://chartio.com/resources/tutorials/how-to-rename-a-database-in-mysql/)
```bash
-- 数据库数据导入
# mysqldump -u root -p"m6s1l@#2!" -R bestphoto > bestphoto.sql
# mysqladmin -u root -p"m6s1l@#2!" create yitieyilu_bp
# mysql -u root -p"m6s1l@#2!" yitieyilu_bp < bestphoto.sql
-- 用户权限赋予
# mysql -u root -p"m6s1l@#2!";
> GRANT ALL PRIVILEGES ON yitieyilu_bp.* TO 'syscorer'@'%';
> GRANT EXECUTE ON PROCEDURE yitieyilu_bp.* TO 'syscorer'@'%';
> flush privileges;
# -------------------------------------------------------------------
# mysqldump -u root -p"m6s1l@#2!" -R yanzhi > yanzhi.sql
# mysqladmin -u root -p"m6s1l@#2!" create yitieyilu_vrpano
# mysql -u root -p"m6s1l@#2!" yitieyilu_vrpano < yanzhi.sql
-- 用户权限赋予
# mysql -u root -p"m6s1l@#2!";
> GRANT ALL PRIVILEGES ON yitieyilu_vrpano.* TO 'syscorer'@'%';
> GRANT EXECUTE ON PROCEDURE yitieyilu_vrpano.* TO 'syscorer'@'%';
> flush privileges;
```

## mysql单索引和联合索引的区别

> 靠左原则
[参考文档](https://blog.csdn.net/Abysscarry/article/details/80792876)

索引如何建立,及其如何使用,参考: https://www.toutiao.com/i6695892976922526212/
@@ -0,0 +1,108 @@
---
title: 5月31日整理
---

## springboot 异步/多线程处理 async

### 多线程的几个概念
- coreSize 核心线程 ,这里设置为 **8**
- queueCapacity 当核心线程都在跑任务,还有多余的任务会存到此处,这里设置为 **20**
- maxSize 如果queueCapacity存满了,还有任务就会启动更多的线程,直到线程数达到maxPoolSize。如果还有任务,则根据拒绝策略进行处理。
,这里设置为 **15** ,超过将会按照**拒绝策略**进行处理
- keepAlive 线程存活时间

> 所以以上的设置,保证了最大只有15个线程在跑任务
1. 当线程数量<8的时候,如果有新的线程需要执行,则以前的线程不会销毁重复利用,直到启动的线程达到8个的时候,才会重复利用核心线程
2. 也就是说如果启动的线程是<=28个,总运行这28的线程的一直是线程池中的8个核心线程交替执行这些线程。
1. 当启动的线程>28个,此时启动新的线程,直到总线程数量达到maxSize
2. 当启动的运行总线程> 15个的时候,此处会安装下面的拒绝策略进行处理线程
拒绝策略如下:

1. 由任务调用线程执行 `new ThreadPoolExecutor.CallerRunsPolicy();`
2. 抛异常 `new ThreadPoolExecutor.AbortPolicy();`
3. 多余的直接抛弃 `new ThreadPoolExecutor.DiscardPolicy();`
4. 根据FIFO(先进先出)抛弃队列里任务 `new ThreadPoolExecutor.DiscardOldestPolicy();`

而跟进代码发现:`TaskExecutionAutoConfiguration`类实现了`ThreadPoolTaskExecutor` bean,我一直都是用的是`TaskExecutor`,直到最近我发现这个bean异步操作后不能返回异步的结果。
所以这里推荐的还是使用`ThreadPoolTaskExecutor``AsyncTaskExecutor`,二者都可以返回多线程执行的结果。如下所示:

![async task](./img/async-task.png)


::: warning 空闲的coreSize线程
空闲的线程不占用内存,参考文档:[stackoverflow](https://stackoverflow.com/questions/43795545/is-idle-thread-taking-cpu-execute-time-in-java-executors)
:::


### ThreadPoolTaskExecutor 等待所有的线程执行完成 `future.get()`

```java
@Service
@Slf4j
public class AsyncService {
@Autowired
private ThreadPoolTaskExecutor taskExecutor;
public void longTask() throws ExecutionException, InterruptedException {
List<ListenableFuture<Integer>> alllist = Lists.newArrayList();
IntStream.range(0, 200).forEach(intValue->{
ListenableFuture<Integer> thread = taskExecutor.submitListenable(() -> {
String name = Thread.currentThread().getName();
log.info("线程: {}", name);
Thread.sleep(5 * 1000);
log.info("结束: {}", name);
return intValue;
});
alllist.add(thread);
});
log.info("Waiting for everything to finish...");
for (ListenableFuture<Integer> future : alllist) {
// 此处的get方法会等待该线程执行完成
Integer threadIndex = future.get();
log.info("thread: {}, is done: {}", threadIndex, future.isDone());
}
}
}
```

## 遍历修改List中的对象属性

```java
List<JobListEntity> newRecord = records.stream().map(record -> {
String jobName = record.getJobName();
try {
JobDetail jobDetail = scheduler.getJobDetail(new JobKey(jobName, jobName));
JobDataMap jobDataMap = jobDetail.getJobDataMap();
record.setJobData(jobDataMap);
} catch (SchedulerException e) {
e.printStackTrace();
}
return record;
}).collect(Collectors.toList());
```

或者如下代码:

```java
records.forEach(record->{
String jobName = record.getJobName();
try {
JobDetail jobDetail = scheduler.getJobDetail(new JobKey(jobName, jobName));
JobDataMap jobDataMap = jobDetail.getJobDataMap();
record.setJobData(jobDataMap);
} catch (SchedulerException e) {
e.printStackTrace();
}
});
```

## mybatis `Blob`字段类型转换

::: warning MYSQL的BLOB /CBLOB 字段
> 经确认mybatis对应的Blob数据库类型不是`java.sql.Blob`类型,否则获取的结果是null,应该对应的是`byte[]`,而`clob`对应的则是 `String`
::: warning
Binary file not shown.

0 comments on commit 9ce3cc8

Please sign in to comment.
You can’t perform that action at this time.