当前位置: 首页 > news >正文

普通Java工程可执行JAR两种打包方式探讨

文章目录

  • 一、需求概述
  • 二、代码结构
  • 三、运行结果
  • 四、打包设置
    • 1. 一体化可执行包
    • 2. 带外部依赖lib的可执行包
  • 五、打包运行
    • 1. 源码放送
    • 2. 打包执行
    • 3. 打包结果

一、需求概述

普通Java工程 docker-show 实现了定时打印docker应用信息,现在需要将其打包成可执行Jar部署到服务器端运行。

打包方式分为2种:

  1. 一体化可执行包
  2. 带外部依赖lib的可执行包

二、代码结构

在这里插入图片描述

三、运行结果

此项目使用了线程池定时打印docker应用名,端口信息
在这里插入图片描述
在这里插入图片描述

四、打包设置

1. 一体化可执行包

pom文件中引入 maven-assembly-plugin插件,核心配置

			<!-- 方式一:带dependencies运行包 --><plugin><artifactId>maven-assembly-plugin</artifactId><version>3.5.0</version><configuration><appendAssemblyId>false</appendAssemblyId><archive><manifest><mainClass>com.fly.simple.MainRun</mainClass></manifest></archive><descriptorRefs><!--将所有外部依赖JAR都加入生成的JAR包--><descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs></configuration><executions><execution><!-- 配置执行器 --><id>make-assembly</id><phase>package</phase><!-- 绑定到package阶段 --><goals><goal>single</goal><!-- 只运行一次 --></goals></execution></executions></plugin>

2. 带外部依赖lib的可执行包

pom文件中引入 maven-dependency-plugin、maven-jar-plugin插件,核心配置

			<!-- 方式二:外部依赖lib目录运行包 --><!-- 将项目依赖包复制到<outputDirectory>指定的目录下 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-dependency-plugin</artifactId><version>3.1.2</version><executions><execution><id>copy-dependencies</id><phase>package</phase><goals><goal>copy-dependencies</goal></goals><configuration><outputDirectory>${project.build.directory}/lib</outputDirectory><excludeArtifactIds>lombok</excludeArtifactIds><includeScope>runtime</includeScope><!-- 默认为test,包含所有依赖 --></configuration></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><version>3.2.0</version><configuration><archive><manifest><addClasspath>true</addClasspath><classpathPrefix>lib</classpathPrefix><mainClass>com.fly.simple.MainRun</mainClass></manifest><manifestEntries><Class-Path>./</Class-Path></manifestEntries></archive></configuration></plugin>

五、打包运行

1. 源码放送

https://gitcode.com/00fly/demo

git clone https://gitcode.com/00fly/demo.git

或者使用下面的备份文件恢复成原始的项目代码

如何恢复,请移步查阅:神奇代码恢复工具

//goto pom-deps.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.fly</groupId><artifactId>docker-show</artifactId><version>0.0.1</version><name>java-depend</name><url>http://maven.apache.org</url><packaging>jar</packaging><properties><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-slf4j-impl</artifactId><version>2.12.1</version></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.5</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.12</version><scope>provided</scope></dependency></dependencies><build><finalName>${project.artifactId}</finalName><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin><!-- 方式一:带dependencies运行包 --><plugin><artifactId>maven-assembly-plugin</artifactId><version>3.5.0</version><configuration><appendAssemblyId>false</appendAssemblyId><archive><manifest><mainClass>com.fly.simple.MainRun</mainClass></manifest></archive><descriptorRefs><!--将所有外部依赖JAR都加入生成的JAR--><descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs></configuration><executions><execution><!-- 配置执行器 --><id>make-assembly</id><phase>package</phase><!-- 绑定到package阶段 --><goals><goal>single</goal><!-- 只运行一次 --></goals></execution></executions></plugin></plugins></build>
</project>
//goto pom-lib.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.fly</groupId><artifactId>docker-show</artifactId><version>0.0.1</version><name>java-depend</name><url>http://maven.apache.org</url><packaging>jar</packaging><properties><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-slf4j-impl</artifactId><version>2.12.1</version></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.5</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.12</version><scope>provided</scope></dependency></dependencies><build><finalName>${project.artifactId}</finalName><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin><!-- 方式二:外部依赖lib目录运行包 --><!-- 将项目依赖包复制到<outputDirectory>指定的目录下 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-dependency-plugin</artifactId><version>3.1.2</version><executions><execution><id>copy-dependencies</id><phase>package</phase><goals><goal>copy-dependencies</goal></goals><configuration><outputDirectory>${project.build.directory}/lib</outputDirectory><excludeArtifactIds>lombok</excludeArtifactIds><includeScope>runtime</includeScope><!-- 默认为test,包含所有依赖 --></configuration></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><version>3.2.0</version><configuration><archive><manifest><addClasspath>true</addClasspath><classpathPrefix>lib</classpathPrefix><mainClass>com.fly.simple.MainRun</mainClass></manifest><manifestEntries><Class-Path>./</Class-Path></manifestEntries></archive></configuration></plugin></plugins></build>
</project>
//goto pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.fly</groupId><artifactId>docker-show</artifactId><version>0.0.1</version><name>java-depend</name><url>http://maven.apache.org</url><packaging>jar</packaging><properties><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-slf4j-impl</artifactId><version>2.12.1</version></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.5</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.12</version><scope>provided</scope></dependency></dependencies><build><finalName>${project.artifactId}</finalName><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin><!-- 方式一:带dependencies运行包 --><plugin><artifactId>maven-assembly-plugin</artifactId><version>3.5.0</version><configuration><appendAssemblyId>true</appendAssemblyId><archive><manifest><mainClass>com.fly.simple.MainRun</mainClass></manifest></archive><descriptorRefs><!--将所有外部依赖JAR都加入生成的JAR--><descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs></configuration><executions><execution><!-- 配置执行器 --><id>make-assembly</id><phase>package</phase><!-- 绑定到package阶段 --><goals><goal>single</goal><!-- 只运行一次 --></goals></execution></executions></plugin><!-- 方式二:外部依赖lib目录运行包 --><!-- 将项目依赖包复制到<outputDirectory>指定的目录下 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-dependency-plugin</artifactId><version>3.1.2</version><executions><execution><id>copy-dependencies</id><phase>package</phase><goals><goal>copy-dependencies</goal></goals><configuration><outputDirectory>${project.build.directory}/lib</outputDirectory><excludeArtifactIds>lombok</excludeArtifactIds><includeScope>runtime</includeScope><!-- 默认为test,包含所有依赖 --></configuration></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><version>3.2.0</version><configuration><archive><manifest><addClasspath>true</addClasspath><classpathPrefix>lib</classpathPrefix><mainClass>com.fly.simple.MainRun</mainClass></manifest><manifestEntries><Class-Path>./</Class-Path></manifestEntries></archive></configuration></plugin></plugins></build>
</project>
//goto src\main\java\com\fly\simple\Executor.java
package com.fly.simple;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;import lombok.extern.slf4j.Slf4j;@Slf4j
public class Executor
{private static String DOCKER_PS_CMD = "docker ps --format \"{{.Names}} {{.Ports}}\"";/*** execute命令* * @param command* @throws IOException* @see [类、类#方法、类#成员]*/public static List<String> execute(String command)throws IOException{List<String> resultList = new ArrayList<>();String[] cmd = SystemUtils.IS_OS_WINDOWS ? new String[] {"cmd", "/c", command} : new String[] {"/bin/sh", "-c", command};Process ps = Runtime.getRuntime().exec(cmd);try (InputStream in = ps.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(in))){String line;while ((line = br.readLine()) != null){resultList.add(line);}}return resultList;}/*** 获取docker相关信息* * @throws IOException*/@Deprecatedpublic static void printPorts1()throws IOException{Map<String, Set<String>> map = new TreeMap<>();for (String line : execute(DOCKER_PS_CMD)){log.info("{}", line);String name = StringUtils.substringBefore(line, " ");Set<String> ports =Stream.of(StringUtils.substringAfter(line, " ").split(",")).map(p -> StringUtils.substringBetween(p, ":", "->")).filter(StringUtils::isNotBlank).map(p -> p.replace(":", "")).sorted().collect(Collectors.toSet());map.put(name, ports);}log.info("######## {}", map);}/*** 获取docker相关信息* * @throws IOException*/public static void printPorts()throws IOException{Map<String, Set<String>> map = new TreeMap<>();execute(DOCKER_PS_CMD).stream().map(line -> Collections.singletonMap(StringUtils.substringBefore(line, " "),Stream.of(StringUtils.substringAfter(line, " ").split(",")).map(p -> StringUtils.substringBetween(p, ":", "->")).filter(StringUtils::isNotBlank).map(p -> p.replace(":", "")).sorted().collect(Collectors.toSet()))).forEach(it -> map.putAll(it));log.info("######## {}", map);}
}
//goto src\main\java\com\fly\simple\MainRun.java
package com.fly.simple;import java.io.IOException;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;public class MainRun
{/*** 线程池保证程序一直运行* * @param args*/public static void main(String[] args){ScheduledExecutorService service = new ScheduledThreadPoolExecutor(1);service.scheduleAtFixedRate(() -> {try{Executor.printPorts();}catch (IOException e){e.printStackTrace();}}, 2, 10, TimeUnit.SECONDS);}
}
//goto src\main\resources\log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="off" monitorInterval="0"><appenders><console name="Console" target="system_out"><patternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /></console></appenders><loggers><root level="INFO"><appender-ref ref="Console" /></root></loggers>
</configuration>

2. 打包执行

#完整打包
mvn clean package#一体化可执行包
mvn clean package -f pom-deps.xml#带外部依赖lib的可执行包
mvn clean package -f pom-lib.xml

3. 打包结果

在这里插入图片描述


有任何问题和建议,都可以向我提问讨论,大家一起进步,谢谢!

-over-

相关文章:

普通Java工程可执行JAR两种打包方式探讨

文章目录 一、需求概述二、代码结构三、运行结果四、打包设置1. 一体化可执行包2. 带外部依赖lib的可执行包 五、打包运行1. 源码放送2. 打包执行3. 打包结果 一、需求概述 普通Java工程 docker-show 实现了定时打印docker应用信息&#xff0c;现在需要将其打包成可执行Jar部署…...

开源博客项目Blog .NET Core源码学习(13:App.Hosting项目结构分析-1)

开源博客项目Blog的App.Hosting项目为MVC架构的&#xff0c;主要定义或保存博客网站前台内容显示页面及后台数据管理页面相关的控制器类、页面、js/css/images文件&#xff0c;页面使用基于layui的Razor页面&#xff08;最早学习本项目就是想学习layui的用法&#xff0c;不过最…...

Vue的双向绑定v-model详细介绍

使用&#xff1a; 比如用户在登录注册时需要提交账号密码&#xff1b; 比如用户创建&#xff0c;更新时&#xff0c;需要提交一些数据&#xff1b; v-model指令可以在表单 input、textarea以及select元素上创建双向绑定&#xff1b; 它会根据控件类型自动选取正确的方法来更…...

AWS入门实践-S3对象存储的基本用法

AWS S3(Simple Storage Service)是亚马逊云服务提供的一种高度可扩展、安全且经济高效的对象存储服务。它允许用户在任何位置存储和检索任意数量的数据,非常适合存储和分发静态文件、备份数据以及作为数据湖的存储层。 一、S3上传和下载文件&#xff08;AWS门户&#xff09; …...

el-tree-v2渲染树形大数据并设置默认展开

el-tree-v2无 el-tree中默认展开节点的属性&#xff0c;需要自行设置 default-expand-all是否默认展开所有节点 需求&#xff1a;首次默认展开全部节点 实现1尝试失败&#xff1a;增加设置了属性 :default-expand-keys"props.treeData.map(itemitem.id)"无效&…...

损失函数篇 | YOLOv8更换损失函数之MPDIoU(23年7月首发论文)

前言:Hello大家好,我是小哥谈。损失函数是机器学习中用来衡量模型预测值与真实值之间差异的函数。在训练模型时,我们希望通过不断调整模型参数,使得损失函数的值最小化,从而使得模型的预测值更加接近真实值。不同的损失函数适用于不同的问题,例如均方误差损失函数适用于回…...

【力扣】200.岛屿数量(染色法DFS深搜)

岛屿数量 题目描述 链接:力扣&#xff1a;200.岛屿数量 给你一个由 1&#xff08;陆地&#xff09;和 0&#xff08;水&#xff09;组成的的二维网格&#xff0c;请你计算网格中岛屿的数量。 岛屿总是被水包围&#xff0c;并且每座岛屿只能由水平方向和/或竖直方向上相邻的陆…...

达梦配置ODBC连接

达梦配置ODBC连接 基础环境 操作系统&#xff1a;Red Hat Enterprise Linux Server release 7.9 (Maipo) 数据库版本&#xff1a;DM Database Server 64 V8 架构&#xff1a;单实例1 下载ODBC包 下载网址&#xff1a;https://www.unixodbc.org/ unixODBC-2.3.0.tar.gz2 编译并…...

独孤思维:高客单价项目,必须来一个

01 上次和水龙聊完以后&#xff0c;完成了图书电商项目小报童的梳理。 而且还让我规划后端低转高产品的设计。 目前独孤&#xff0c;准备以图书电商项目私教作为切入点&#xff0c;捆绑自己的合伙人。 设计高客单价项目。 所以&#xff0c;独孤4月的副业规划目标&#xff…...

学习java第三十二天

Spring 会利用AutowiredAnnotationBeanPostProcessor.postProcessMergedBeanDefinition() 找出注入点并缓存&#xff0c; 找注入点的流程为&#xff1a; 遍历当前类的所有的属性字段 Field 查看字段上是否存在 Autowired、Value、Inject 中的其中任意一个&#xff0c;存在则认…...

力扣150. 逆波兰表达式求值

思路&#xff1a;又是有消消乐的感觉&#xff0c;只不过这里是遇到一个操作符号&#xff0c;就消掉两个数字合并成一个新数&#xff1b;所以想到用栈结构来处理&#xff1b;用一个栈来放当前遍历过的数字&#xff0c;当遍历遇到操作符时&#xff0c;就把前面最新入栈的两个数取…...

hololens 2 投屏 报错

使用Microsoft HoloLens投屏时&#xff0c;ip地址填对了&#xff0c;但是仍然报错&#xff0c;说hololens 2没有打开&#xff0c; 首先检查 开发人员选项 都打开&#xff0c;设备门户也打开 然后检查系统–体验共享&#xff0c;把共享都打开就可以了...

初次在 GitHub 建立仓库以及公开代码的流程 - 公开代码

初次在 GitHub 建立仓库以及公开代码的流程 - 公开代码 References 在已有仓库中添加代码并公开。 git clone 已有仓库 将已有仓库 clone 到本地的开发环境中。 strongforeverstrong:~$ mkdir github_work strongforeverstrong:~$ cd github_work/ strongforeverstrong:~/git…...

论文笔记 - :MonoLSS: Learnable Sample Selection For Monocular 3D Detection

论文笔记✍MonoLSS: Learnable Sample Selection For Monocular 3D Detection &#x1f4dc; Abstract &#x1f528; 主流做法限制 &#xff1a; 以前的工作以启发式的方式使用特征来学习 3D 属性&#xff0c;没有考虑到不适当的特征可能会产生不利影响。 &#x1f528; 本…...

LVS、HAProxy

集群&#xff1a;将很多个机器组织到一起&#xff0c;作为一个整体对外提供服务。集群在扩展性、性能方面都可以做到很灵活。集群的分类&#xff1a;负载均衡集群&#xff1a;Load Balance。高可用集群&#xff1a;High Available。高性能集群&#xff1a;High Performance Com…...

开发环境->生产环境

1、数据迁移 不涉及docker # 以数据库用户导出数据 mysqldump -h 192.168.1.168 -P 3307 -u abragent -pabragebb17 abragent > abragent.sql# 以root用户导出数据 mysqldump -h 192.168.1.168 -P 3307 -u root -p8d3Ba1b abragent > abragent.sql 涉及docker …...

基于AI智能识别技术的智慧展览馆视频监管方案设计

一、建设背景 随着科技的不断进步和社会安全需求的日益增长&#xff0c;展览馆作为展示文化、艺术和科技成果的重要场所&#xff0c;其安全监控系统的智能化升级已成为当务之急。为此&#xff0c;旭帆科技&#xff08;TSINGSEE青犀&#xff09;基于视频智能分析技术推出了展览…...

Leetcode-894-所有可能的真二叉树-c++

题目详见https://leetcode.cn/problems/all-possible-full-binary-trees/ 主搞动态规划&#xff0c;因为这玩意儿我还不是很懂 关于节点个数为奇数偶数的证明请见官方题解方法一中的如下内容&#xff1a; 这里DP的一个主要思想是&#xff1a;对于任何一个满二叉树&#xff…...

Django DRF视图

文章目录 一、DRF类视图介绍APIViewGenericAPIView类ViewSet类ModelViewSet类重写方法 二、Request与ResponseRequestResponse 参考 一、DRF类视图介绍 在DRF框架中提供了众多的通用视图基类与扩展类&#xff0c;以简化视图的编写。 • View&#xff1a;Django默认的视图基类&…...

SQLite全文搜索引擎:实现原理、应用实践和版本差异

文章目录 一、实现原理1.1 倒排索引1.2 虚拟表 二、应用在工程上的实施方法2.1 创建FTS虚拟表2.2 插入数据2.3 全文搜索2.4 关联普通表2.5 更新和删除数据2.6 优化FTS虚拟表2.7 小结 三、FTS3、FTS4和FTS5的区别3.1 FTS33.2 FTS43.3 FTS53.4 小结 四、更新SQLite的FTS版本的步骤…...

观成科技:隐蔽隧道工具Ligolo-ng加密流量分析

1.工具介绍 Ligolo-ng是一款由go编写的高效隧道工具&#xff0c;该工具基于TUN接口实现其功能&#xff0c;利用反向TCP/TLS连接建立一条隐蔽的通信信道&#xff0c;支持使用Let’s Encrypt自动生成证书。Ligolo-ng的通信隐蔽性体现在其支持多种连接方式&#xff0c;适应复杂网…...

反向工程与模型迁移:打造未来商品详情API的可持续创新体系

在电商行业蓬勃发展的当下&#xff0c;商品详情API作为连接电商平台与开发者、商家及用户的关键纽带&#xff0c;其重要性日益凸显。传统商品详情API主要聚焦于商品基本信息&#xff08;如名称、价格、库存等&#xff09;的获取与展示&#xff0c;已难以满足市场对个性化、智能…...

【Oracle APEX开发小技巧12】

有如下需求&#xff1a; 有一个问题反馈页面&#xff0c;要实现在apex页面展示能直观看到反馈时间超过7天未处理的数据&#xff0c;方便管理员及时处理反馈。 我的方法&#xff1a;直接将逻辑写在SQL中&#xff0c;这样可以直接在页面展示 完整代码&#xff1a; SELECTSF.FE…...

零基础设计模式——行为型模式 - 责任链模式

第四部分&#xff1a;行为型模式 - 责任链模式 (Chain of Responsibility Pattern) 欢迎来到行为型模式的学习&#xff01;行为型模式关注对象之间的职责分配、算法封装和对象间的交互。我们将学习的第一个行为型模式是责任链模式。 核心思想&#xff1a;使多个对象都有机会处…...

在鸿蒙HarmonyOS 5中使用DevEco Studio实现录音机应用

1. 项目配置与权限设置 1.1 配置module.json5 {"module": {"requestPermissions": [{"name": "ohos.permission.MICROPHONE","reason": "录音需要麦克风权限"},{"name": "ohos.permission.WRITE…...

C# 求圆面积的程序(Program to find area of a circle)

给定半径r&#xff0c;求圆的面积。圆的面积应精确到小数点后5位。 例子&#xff1a; 输入&#xff1a;r 5 输出&#xff1a;78.53982 解释&#xff1a;由于面积 PI * r * r 3.14159265358979323846 * 5 * 5 78.53982&#xff0c;因为我们只保留小数点后 5 位数字。 输…...

JVM虚拟机:内存结构、垃圾回收、性能优化

1、JVM虚拟机的简介 Java 虚拟机(Java Virtual Machine 简称:JVM)是运行所有 Java 程序的抽象计算机,是 Java 语言的运行环境,实现了 Java 程序的跨平台特性。JVM 屏蔽了与具体操作系统平台相关的信息,使得 Java 程序只需生成在 JVM 上运行的目标代码(字节码),就可以…...

SQL慢可能是触发了ring buffer

简介 最近在进行 postgresql 性能排查的时候,发现 PG 在某一个时间并行执行的 SQL 变得特别慢。最后通过监控监观察到并行发起得时间 buffers_alloc 就急速上升,且低水位伴随在整个慢 SQL,一直是 buferIO 的等待事件,此时也没有其他会话的争抢。SQL 虽然不是高效 SQL ,但…...

MySQL 8.0 事务全面讲解

以下是一个结合两次回答的 MySQL 8.0 事务全面讲解&#xff0c;涵盖了事务的核心概念、操作示例、失败回滚、隔离级别、事务性 DDL 和 XA 事务等内容&#xff0c;并修正了查看隔离级别的命令。 MySQL 8.0 事务全面讲解 一、事务的核心概念&#xff08;ACID&#xff09; 事务是…...

Python Einops库:深度学习中的张量操作革命

Einops&#xff08;爱因斯坦操作库&#xff09;就像给张量操作戴上了一副"语义眼镜"——让你用人类能理解的方式告诉计算机如何操作多维数组。这个基于爱因斯坦求和约定的库&#xff0c;用类似自然语言的表达式替代了晦涩的API调用&#xff0c;彻底改变了深度学习工程…...