上一页 1 2 3 4 5 6 7 ··· 69 下一页
摘要: python3 import base64 userpass = username + ':' + password encoded_u = base64.b64encode(userpass.encode()).decode() headers = {"Authorization" : "Basi 阅读全文
posted @ 2022-09-11 06:46 jihite 阅读(49) 评论(0) 推荐(0) 编辑
摘要: 设计模式 在软件工程中,设计模式(design pattern)是对软件设计中普遍存在(反复出现)的各种问题,所提出的解决方案。 这个术语是由埃里希·伽玛(Erich Gamma)等人在1990年代从建筑设计领域引入到计算机科学的。 使用设计模式是为了写出可扩展、可读、可维护的高质量代码。 为何要学 阅读全文
posted @ 2022-07-24 22:19 jihite 阅读(315) 评论(0) 推荐(0) 编辑
摘要: 在Java应用中,我们往往会使用spring-kafka组件简单的设置一下group_id, topic就开始消费消息了,其实这样会埋下巨大的安全隐患,即当消费速度过慢时有可能会触发rebalance, 这批消息被分配到另一个消费者,然后新的消费者还会消费过慢,再次rebalance, 这样一直恶性 阅读全文
posted @ 2022-06-08 09:30 jihite 阅读(2635) 评论(0) 推荐(0) 编辑
摘要: 定义 是UNIX中的分叉函数,将运行着的程序分成两个完全一样的进程。 fork() 有返回值: 0: 返回到新创建的子进程 负值:创建子进程失败 正数: 返回父进程或调用者 返回值: 若成功调用一次则返回两个值,子进程返回0,父进程返回子进程ID;否则,出错返回-1 示例 import os imp 阅读全文
posted @ 2022-04-21 22:02 jihite 阅读(64) 评论(0) 推荐(0) 编辑
摘要: 需求 对变量并发执行10000次相加 示例1:裸奔 package main import ( "fmt" "sync" ) var xx int var wg111 sync.WaitGroup func add() { xx++ wg111.Done() } func main() { wg11 阅读全文
posted @ 2022-02-13 23:02 jihite 阅读(110) 评论(2) 推荐(0) 编辑
摘要: 需求 高并发场景下,操作只执行一次,如读取配置、单例模式 实现 Go 的sync模块提供了只执行一次的解决方案:sync.Once, 它只有一个函数:Do func (o *Once) Do(f func()) {} 示例1:读取一次配置文件 package main import ( "fmt" 阅读全文
posted @ 2022-02-12 13:46 jihite 阅读(65) 评论(0) 推荐(0) 编辑
摘要: 需求 读写共享map #1 常规map package main import ( "fmt" "strconv" "sync" ) func _110Test1() { wg := sync.WaitGroup{} mp := make(map[string]int) for i := 0; i 阅读全文
posted @ 2022-02-09 09:52 jihite 阅读(43) 评论(0) 推荐(0) 编辑
摘要: 不加锁 package main import ( "fmt" "sync" ) var x=0 var wg107 sync.WaitGroup func add1() { for i := 0; i < 50000; i++ { x += 1 } wg107.Done() } func test 阅读全文
posted @ 2022-02-09 09:23 jihite 阅读(85) 评论(0) 推荐(0) 编辑
摘要: 示例 package main import "fmt" func main() { ch := make(chan int, 1) for i := 0; i < 10; i++ { select { case x := <-ch: fmt.Println(x) case ch <- i: } } 阅读全文
posted @ 2022-02-06 22:39 jihite 阅读(70) 评论(0) 推荐(0) 编辑
摘要: 背景 在实际工作中,我们总会限制goroutine数量——worker pool模式,控制goroutine数量,避免goroutine泄露与膨胀 示例 package main import ( "fmt" "time" ) func worker(w int, jobs <-chan int, 阅读全文
posted @ 2022-02-06 18:33 jihite 阅读(153) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 ··· 69 下一页