spring13-AspectJ

nexthexonextbutterflyvolantisyearnyiliashokaindigoapollolandscapecactusmateryicarusfluidmaterial 1. AspectJ1.1. AspectJ介绍AspectJ官网^4 AspectJ文档^1 1.1.1. pointcutspointcuts指的是程序中的某些链接点(某些时机),例如call(void Point.setX(int))表示:调用类Point的setX(int)方法时 pointcuts可以使用与或非表达式(||,&&,!)连接,比如 call(void Point.setX(int)) || call(void Point.setY(int)) pointcuts可以被定义为变量,如下面代码中的move() 123456pointcut move(): call(void FigureElement.setXY(int,int)) || call(void Point.setX(int)) || call(void Point.setY(int)) || call(void Line.setP1(Point)) || call(void Line.setP2(Point)); 当然pointcuts定义的时候还可以使用通配符,比如call(void Figure.make*(..))代表Figure的以make开头且返回值为void的方法(不关心参数)调用的时候。比如call(public * Figure.* (..))代表Figure的任何方法(不关心方法名,参数,返回值)调用的时候。     阅读全文
fightinggg's avatar
fightinggg 3月 31, 2022

C++引用的秘密

nexthexonextbutterflyvolantisyearnyiliashokaindigoapollolandscapecactusmateryicarusfluidmaterial 0. 一个错误的概念123456int main() { int a = 111; int &b = a; b = 222; std::cout<<&a<<&b;} 我们能看到这里输出的两个值相同。 错误1: 很多人认为这里的b就是a,a就是b,a和b的地址是一样的,如下图。 但是笔者要说,其实这个概念是有问题的,a是a,b是b,a和b并不是同一个地址。     阅读全文
fightinggg's avatar
fightinggg 2月 16, 2022

Springfox使用

    阅读全文
fightinggg's avatar
fightinggg 1月 13, 2022

Go入门-常见陷阱

    阅读全文
fightinggg's avatar
fightinggg 11月 03, 2021

Go进阶-Module

nexthexonextbutterflyvolantisyearnyiliashokaindigoapollolandscapecactusmateryicarusfluidmaterial 1. Module使用在文章Go入门-Go语言从入门到进阶实战中,我们介绍了GO项目的结构,但是没有解释其中的一个文件go.mod, 这其实是模块的意思。在go.mod中可以引入go的依赖。 123456require ( github.com/golang/mock v1.4.4 github.com/golang/protobuf v1.4.3 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/stretchr/testify v1.6.1) 这里简单介绍一下,注意到这里是库名加版本号。当我们引入了依赖管理以后,就可以在自己的项目中直接import三方包了。 2. Module 的历史 Go modules 是 Go 语言的依赖解决方案,发布于 Go1.11,Go1.14 上已经明确建议生产上使用了 一开始go发布的时候是没有包管理的 go get命令会根据路径,把相应的模块获取并保存在$GOPATH/src 也没有版本的概念,master 就代表稳定的版本 原文: 😊 在Go Module出现以前,我们使用Go Get获取库,库会直接下载到GOPATH目录的src文件夹下,很好用但是有一个问题-版本兼容问题。 当两个库依赖分别同一个库的v1和v2版本的时候,如果v1和v2不兼容,那么会导致这两个库无法同时使用。 后来官方采用了vgo方案来解决GO的依赖管理问题,也就是现在的Go modules。     阅读全文
fightinggg's avatar
fightinggg 10月 22, 2021

Go入门-Effective-Go

nexthexonextbutterflyvolantisyearnyiliashokaindigoapollolandscapecactusmateryicarusfluidmaterial 1. Effective GOhttps://github.com/bingohuang/effective-go-zh-en 2. 格式化在最开始学习GO的时候,写了几篇Blog,发现代码里面的对齐都是TAB,这让我很困惑,知道现在才知道,GO语言,默认使用TAB进行对齐。 当然GO还有自己的空格规则x<<8 + y<<16,向这份代码,我们根据空格就能知道计算的优先级了。 3. 注释3.1. 包注释Go语言要求package语句前加上注释,来介绍整个包,如果package包含多个文件,则只需要在其中一个文件中标注即可。 1234567891011121314151617181920/*Package regexp implements a simple library for regular expressions.The syntax of the regular expressions accepted is: regexp: concatenation { '|' concatenation } concatenation: { closure } closure: term [ '*' | '+' | '?' ] term: '^' '$' '.' character '[' [ '^' ] character-ranges ']' '(' regexp ')'*/package regexp     阅读全文
fightinggg's avatar
fightinggg 10月 19, 2021

Go进阶-Web框架

nexthexonextbutterflyvolantisyearnyiliashokaindigoapollolandscapecactusmateryicarusfluidmaterial 0. 前言简单介绍Beego和Gin,水一水文章。 1.1. 安装Beego库1go get github.com/astaxie/beego 同时安装Bee工具 1go get github.com/beego/bee 看到如下内容代表安装成功 12345678910111213141516171819202122232425262728293031323334353637383940414243444546s@HELLOWANG-MB1 ~ % go get github.com/astaxie/beegogo: downloading github.com/astaxie/beego v1.12.3go: downloading github.com/prometheus/client_golang v1.7.0go: downloading github.com/hashicorp/golang-lru v0.5.4go: downloading golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550go: downloading github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644go: downloading github.com/prometheus/common v0.10.0go: downloading github.com/prometheus/client_model v0.2.0go: downloading github.com/prometheus/procfs v0.1.3go: downloading github.com/beorn7/perks v1.0.1go: downloading golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1go: downloading github.com/cespare/xxhash/v2 v2.1.1go: downloading github.com/golang/protobuf v1.4.2go: downloading github.com/matttproud/golang_protobuf_extensions v1.0.1go: downloading google.golang.org/protobuf v1.23.0s@HELLOWANG-MB1 ~ % go get github.com/beego/beego: downloading github.com/beego/bee v1.12.3go: downloading github.com/gadelkareem/delve v1.4.2-0.20200619175259-dcd01330766fgo: downloading github.com/gorilla/websocket v1.4.2go: downloading github.com/lib/pq v1.7.0go: downloading github.com/flosch/pongo2 v0.0.0-20200529170236-5abacdfa4915go: downloading github.com/pelletier/go-toml v1.2.0go: downloading github.com/smartwalle/pongo2render v1.0.1go: downloading github.com/spf13/viper v1.7.0go: downloading github.com/astaxie/beego v1.12.1go: downloading github.com/hashicorp/hcl v1.0.0go: downloading github.com/magiconair/properties v1.8.1go: downloading github.com/spf13/afero v1.1.2go: downloading github.com/spf13/cast v1.3.0go: downloading github.com/spf13/jwalterweatherman v1.0.0go: downloading github.com/spf13/pflag v1.0.3go: downloading github.com/subosito/gotenv v1.2.0go: downloading gopkg.in/ini.v1 v1.51.0go: downloading golang.org/x/text v0.3.2go: downloading github.com/sirupsen/logrus v1.6.0go: downloading github.com/cosiner/argv v0.1.0go: downloading github.com/peterh/liner v0.0.0-20170317030525-88609521dc4bgo: downloading github.com/mattn/go-colorable v0.0.9go: downloading github.com/mattn/go-isatty v0.0.3go: downloading golang.org/x/arch v0.0.0-20190927153633-4e8777c89be4go: downloading go.starlark.net v0.0.0-20190702223751-32f345186213go: downloading github.com/konsorten/go-windows-terminal-sequences v1.0.3go get: installing executables with 'go get' in module mode is deprecated. Use 'go install pkg@version' instead. For more information, see https://golang.org/doc/go-get-install-deprecation or run 'go help get' or 'go help install'.     阅读全文
fightinggg's avatar
fightinggg 10月 18, 2021

Go进阶-协程的本质与CPU的争夺

nexthexonextbutterflyvolantisyearnyiliashokaindigoapollolandscapecactusmateryicarusfluidmaterial 1. 从协程谈起很多语言都支持协程,那什么是协程,和线程进程有什么区别呢?这里推荐一篇Blog,笔者直接提取其中最重要的部分 进程、线程 和 协程 之间概念的区别   对于 进程、线程,都是有内核进行调度,有 CPU 时间片的概念,进行 抢占式调度(有多种调度算法)   对于 协程(用户级线程),这是对内核透明的,也就是系统并不知道有协程的存在,是完全由用户自己的程序进行调度的,因为是由用户程序自己控制,那么就很难像抢占式调度那样做到强制的 CPU 控制权切换到其他进程/线程,通常只能进行 协作式调度,需要协程自己主动把控制权转让出去之后,其他协程才能被执行到。  goroutine 和协程区别   本质上,goroutine 就是协程。 不同的是,Golang 在 runtime、系统调用等多方面对 goroutine 调度进行了封装和处理,当遇到长时间执行或者进行系统调用时,会主动把当前 goroutine 的CPU (P) 转让出去,让其他 goroutine 能被调度并执行,也就是 Golang 从语言层面支持了协程。Golang 的一大特色就是从语言层面原生支持协程,在函数或者方法前面加 go关键字就可创建一个协程。 操作系统是不知道协程的,那么应用层如何实现协程呢?下面给一些伪代码 12345678不断循环: 从任务队列获取任务 执行任务,如果任务运行结束: 进行下一轮循环(continue) 如果任务运行时进入阻塞状态: 把当前任务放入队列尾部(挂起) 如果任务主动释放CPU: 把当前任务放入队列尾部(挂起) 我们可以看到,其实这里正在执行的任务就是协程,这样的线程模型,他的CPU利用率非常高,他的协程切换代价非常低,几乎只需要入队出队而已。 但是这样的模型有一个很大的缺点,那就是CPU的公平性,如果一个协程迟迟不退出,且不进行系统调用,也不主动释放CPU,那么,这个协程将造成队头阻塞现象。     阅读全文
fightinggg's avatar
fightinggg 10月 13, 2021

Go入门-Go语言从入门到进阶实战

nexthexonextbutterflyvolantisyearnyiliashokaindigoapollolandscapecactusmateryicarusfluidmaterial 1. 开始学习Go从一本书开始,这本书叫做《Go语言从入门到进阶实战(视频教学版)》,当然这篇Blog并不是所有的内容都来自这本书,毕竟书中也有不足之处。 2. Hello World学啥语言的第一步都是Hello World, 第一步是搭建开发环境,直接下载Goland,创建一个新的工程,点击create     阅读全文
fightinggg's avatar
fightinggg 10月 11, 2021

Java运行时分析工具

nexthexonextbutterflyvolantisyearnyiliashokaindigoapollolandscapecactusmateryicarusfluidmaterial Jpsjps 可以看到运行中的java进程 123sh-4.2$ jps370 xxx.jar180682 Jps Jcmdjcmd可以看到运行中的java进程以及参数 123sh-4.2$ jcmd370 /usr/local/xxx.jar config_path=xxx.yaml180773 sun.tools.jcmd.JCmd Jmapjmap是可以查看整个JVM内存的工具。     阅读全文
fightinggg's avatar
fightinggg 9月 24, 2021