springboot使用lettuce連線池

2022-05-03 12:09:17 字數 3573 閱讀 1100

springboot對連線池的使用非常智慧型,配置檔案中新增lettuce.pool相關配置,則會使用到lettuce連線池,並將相關配置設定為連線池相關引數,(前提是這些引數是springboot配置檔案中內建的,使用自定義引數應該也是可以的,有時間在研究),否則不使用,通過斷點除錯檢視

如過使用redis連線池(無論lettuce還是jedis客戶端,都需要),則需要匯入如下依賴

org.apache.commons

commons-pool2

一、使用lettuce連線池

server.ip=192.168.102.186spring.redis.host=$

spring.redis.port=6379spring.redis.timeout=20000spring.redis.lettuce.pool.max-idle=10spring.redis.lettuce.pool.min-idle=10spring.redis.lettuce.pool.max-active=20spring.redis.lettuce.pool.max-wait=10000

檢視connectionfactory中相關引數

maxidle和minidle均為10,maxtotal為20(對應配置中max-active),maxwaitmillis為10000(對應配置中max-wait),與設定一致

檢視org.apache.commons.pool2.impl.genericobjectpoolconfig原始碼,如下幾個字段需要注意

public

class genericobjectpoolconfigextends baseobjectpoolconfig configuration attribute.

* @see

genericobjectpool#getmaxtotal()

*/public

static

final

int default_max_total = 8;

/*** the default value for the configuration attribute.

* @see

genericobjectpool#getmaxidle()

*/public

static

final

int default_max_idle = 8;

/*** the default value for the configuration attribute.

* @see

genericobjectpool#getminidle()

*/public

static

final

int default_min_idle = 0;

private

int maxtotal =default_max_total;

private

int maxidle =default_max_idle;

private

int minidle =default_min_idle;

/*** get the value for the configuration attribute

* for pools created with this configuration instance.**

@return

the current setting of for this

* configuration instance**

@see

genericobjectpool#getmaxtotal()

*/public

intgetmaxtotal()

/*** set the value for the configuration attribute for

* pools created with this configuration instance.**

@param

maxtotal the new setting of

* for this configuration instance**

@see

genericobjectpool#setmaxtotal(int)

*/public

void setmaxtotal(final

intmaxtotal)

.....

預設maxidle為8,minidle為0,maxtotal為8檢視genericobjectpoolconfig父類baseobjectpoolconfig

public

abstract

class baseobjectpoolconfigextends baseobject implements

cloneable configuration attribute.

* @see

genericobjectpool#getlifo()

* @see

generickeyedobjectpool#getlifo()

*/public

static

final

boolean default_lifo = true

;

/*** the default value for the configuration attribute.

* @see

genericobjectpool#getfairness()

* @see

generickeyedobjectpool#getfairness()

*/public

static

final

boolean default_fairness = false

;

/*** the default value for the configuration attribute.

* @see

genericobjectpool#getmaxwaitmillis()

* @see

generickeyedobjectpool#getmaxwaitmillis()

*/public

static

final

long default_max_wait_millis = -1l;

......

maxwaitmillis預設值為-1二、去掉lettuce pool相關配置

connectionprovider下已經不存在poolconfig,說明未使用連線池

使用let宣告變數

es5宣告變數的問題 1.全域性變數掛載到全域性物件 全域性物件成員汙染問題。let宣告的變數不會掛載到全域性物件。2.允許重複的變數宣告,導致變數被覆蓋。let宣告的變數不允許當前作用域範圍內重複宣告。3.變數提公升 怪異的資料訪問,閉包問題。使用let不會有變數提公升,因此,不能在定義變數之前使...

SpringBoot使用thymeleaf模板

springboot開發的web專案contrller如何跳轉到前端頁面 據說,最流行的還是freemarker和velocity這兩種模板,我們這裡用spring官方推薦的thymeleaf模板 在建立好springboot專案的基礎上,進行如下配置 在pom中到thymeleaf的依賴 org....

Spring Boot使用Undertow做伺服器

1 建立spring boot專案,修改其pom.xml檔案 org.springframework.boot spring boot starter test org.springframework.boot spring boot starter web org.springframework....