mybatis源码学习(三):MappedStatement的解析过程

我们之前介绍过MappedStatement表示的是XML中的一个SQL。类当中的很多字段都是SQL中对应的属性。我们先来了解一下这个类的属性:

public final class MappedStatement {private String resource;private Configuration configuration;//sql的IDprivate String id;//尝试影响驱动程序每次批量返回的结果行数和这个设置值相等private Integer fetchSize;//SQL超时时间private Integer timeout;//Statement的类型,STATEMENT/PREPARE/CALLABLEprivate StatementType statementType;//结果集类型,FORWARD_ONLY/SCROLL_SENSITIVE/SCROLL_INSENSITIVE private ResultSetType resultSetType;//表示解析出来的SQLprivate SqlSource sqlSource;//缓存private Cache cache;//已废弃private ParameterMap parameterMap;//对应的ResultMapprivate List<ResultMap> resultMaps;private boolean flushCacheRequired;private boolean useCache;private boolean resultOrdered;//SQL类型,INSERT/SELECT/DELETEprivate SqlCommandType sqlCommandType;//和SELECTKEY标签有关private KeyGenerator keyGenerator;private String[] keyProperties;private String[] keyColumns;private boolean hasNestedResultMaps;//数据库ID,用来区分不同环境private String databaseId;private Log statementLog;private LanguageDriver lang;//多结果集时private String[] resultSets;MappedStatement() {// constructor disabled
  }...}

对一些重要的字段我都增加了备注,方便理解。其中真正表示SQL的字段是SqlSource这个对象。

SqlSource接口很简单,只有一个getBound方法:

public interface SqlSource {BoundSql getBoundSql(Object parameterObject);}

它有很多实现,需要我们重点关注的是StaticSqlSource,RawSqlSource和DynamicSqlSource。在正式学习他们前,我们先了解一下Mybatis动态SQL和静态SQL的区别。

动态SQL表示这个SQL节点中含有${}或是其他动态的标签(比如,if,trim,foreach,choose,bind节点等),需要在运行时根据传入的条件才能确定SQL,因此对于动态SQL的MappedStatement的解析过程应该是在运行时。

而静态SQL是不含以上这个节点的SQL,能直接解析得到含有占位符形式的SQL语句,而不需要根据传入的条件确定SQL,因此可以在加载时就完成解析。所在在执行效率上要高于动态SQL。

而DynamicSqlSource和RawSqlSource就分别对应了动态SQL和静态SQL,它们都封装了StaticSqlSource。

我们先从简单的入手,了解静态SQL的解析过程。

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="org.apache.ibatis.domain.blog.mappers.AuthorMapper"><select id="selectAllAuthors" resultType="org.apache.ibatis.domain.blog.Author">select * from author</select></mapper>

这是我们要解析的XML文件,mapper节点下只有一个select节点。

public class XmlMapperBuilderTest {@Testpublic void shouldSuccessfullyLoadXMLMapperFile() throws Exception {Configuration configuration = new Configuration();String resource = "org/apache/ibatis/builder/AuthorMapper.xml";InputStream inputStream = Resources.getResourceAsStream(resource);XMLMapperBuilder builder = new XMLMapperBuilder(inputStream, configuration, resource, configuration.getSqlFragments());builder.parse();inputStream.close();}
}

这是我们测试解析过程的代码。我们可以看到解析是由XMLMapperBuilder开始的。我们先了解一下它的字段:

public class XMLMapperBuilder extends BaseBuilder {//用来解析XMLprivate final XPathParser parser;//再解析完成后,用解析所得的属性来帮助创建各个对象private final MapperBuilderAssistant builderAssistant;//保存SQL节点private final Map<String, XNode> sqlFragments;//...  
}

它还从父类中继承了configuration(配置对象),typeAliasRegistry(类型别名注册器)和typeHandlerRegistry(类型处理器注册器)。

接下来看一下它的parse方法:

public void parse() {//判断是否已经加载过资源    if (!configuration.isResourceLoaded(resource)) {//从mapper根节点开始解析configurationElement(parser.evalNode("/mapper"));//将该资源添加到为已经加载过的缓存中
      configuration.addLoadedResource(resource);//将解析的SQL和接口中的方法绑定
      bindMapperForNamespace();}//对一些未完成解析的节点再解析
    parsePendingResultMaps();parsePendingCacheRefs();parsePendingStatements();}

主要的解析过程在configurationElement中:

private void configurationElement(XNode context) {try {//解析mapper的namespace属性,并设置String namespace = context.getStringAttribute("namespace");if (namespace == null || namespace.equals("")) {throw new BuilderException("Mapper's namespace cannot be empty");}builderAssistant.setCurrentNamespace(namespace);//解析<cache-ref>节点,它有一个namespace属性,表示引用该命名空间下的缓存cacheRefElement(context.evalNode("cache-ref"));//解析<cache>节点,可以设置缓存类型和属性,或是指定自定义的缓存cacheElement(context.evalNode("cache"));//已废弃,不再使用    parameterMapElement(context.evalNodes("/mapper/parameterMap"));//解析resultMap节点resultMapElements(context.evalNodes("/mapper/resultMap"));//解析<SQL>节点,SQL节点可以使一些SQL片段被复用     sqlElement(context.evalNodes("/mapper/sql"));//解析SQL语句(select|insert|update|delete节点) buildStatementFromContext(context.evalNodes("select|insert|update|delete"));} catch (Exception e) {throw new BuilderException("Error parsing Mapper XML. The XML location is '" + resource + "'. Cause: " + e, e);}} 

我们关注SQL语句的解析过程,上述buildStatementFromContext(List<XNode>)方法会增加dateBaseId的参数,然后调用另一个重载方法:

private void buildStatementFromContext(List<XNode> list, String requiredDatabaseId) {//遍历XNode节点for (XNode context : list) {//为每个节点创建XMLStatementBuilder对象,final XMLStatementBuilder statementParser = new XMLStatementBuilder(configuration, builderAssistant, context, requiredDatabaseId);try {//解析Node
        statementParser.parseStatementNode();} catch (IncompleteElementException e) {//对不能完全解析的节点添加到incompleteStatement,在parsePendingStatements方法中再解析
        configuration.addIncompleteStatement(statementParser);}}}

先看看XMLStatementBuilder对象:

public class XMLStatementBuilder extends BaseBuilder {private final MapperBuilderAssistant builderAssistant;private final XNode context;private final String requiredDatabaseId;// ...
}
View Code

含有的字段相对简单,不再具体解释。直接看parseStatementNode方法:

 

public void parseStatementNode() {//获取idString id = context.getStringAttribute("id");String databaseId = context.getStringAttribute("databaseId");//验证databaseId是否匹配if (!databaseIdMatchesCurrent(id, databaseId, this.requiredDatabaseId)) {return;}Integer fetchSize = context.getIntAttribute("fetchSize");Integer timeout = context.getIntAttribute("timeout");//已废弃String parameterMap = context.getStringAttribute("parameterMap");//参数类型;将会传入这条语句的参数类的完全限定名或别名。这个属性是可选的,因为 MyBatis 可以通过 TypeHandler 推断出具体传入语句的参数,默认值为 unset。String parameterType = context.getStringAttribute("parameterType");Class<?> parameterTypeClass = resolveClass(parameterType);//结果类型;外部 resultMap 的命名引用。String resultMap = context.getStringAttribute("resultMap");//结果类型;表示从这条语句中返回的期望类型的类的完全限定名或别名。注意如果是集合情形,那应该是集合可以包含的类型,而不能是集合本身。不能和resultMap同时使用。String resultType = context.getStringAttribute("resultType");String lang = context.getStringAttribute("lang");LanguageDriver langDriver = getLanguageDriver(lang);Class<?> resultTypeClass = resolveClass(resultType);//结果集类型;FORWARD_ONLY,SCROLL_SENSITIVE 或 SCROLL_INSENSITIVE 中的一个,默认值为 unset (依赖驱动)。String resultSetType = context.getStringAttribute("resultSetType");//STATEMENT,PREPARED 或 CALLABLE 的一个。这会让 MyBatis 分别使用 Statement,PreparedStatement 或 CallableStatement,默认值:PREPARED。StatementType statementType = StatementType.valueOf(context.getStringAttribute("statementType", StatementType.PREPARED.toString()));ResultSetType resultSetTypeEnum = resolveResultSetType(resultSetType);String nodeName = context.getNode().getNodeName();//SQLCommand类型SqlCommandType sqlCommandType = SqlCommandType.valueOf(nodeName.toUpperCase(Locale.ENGLISH));boolean isSelect = sqlCommandType == SqlCommandType.SELECT;//flushCache;在执行语句时表示是否刷新缓存boolean flushCache = context.getBooleanAttribute("flushCache", !isSelect);//是否对该语句进行二级缓存;默认值:对 select 元素为 true。boolean useCache = context.getBooleanAttribute("useCache", isSelect);//根嵌套结果相关boolean resultOrdered = context.getBooleanAttribute("resultOrdered", false);//引入SQL片段// Include Fragments before parsingXMLIncludeTransformer includeParser = new XMLIncludeTransformer(configuration, builderAssistant);includeParser.applyIncludes(context.getNode());// Parse selectKey after includes and remove them.//处理selectKey
    processSelectKeyNodes(id, parameterTypeClass, langDriver);// Parse the SQL (pre: <selectKey> and <include> were parsed and removed)SqlSource sqlSource = langDriver.createSqlSource(configuration, context, parameterTypeClass);//
    String resultSets = context.getStringAttribute("resultSets");String keyProperty = context.getStringAttribute("keyProperty");String keyColumn = context.getStringAttribute("keyColumn");//设置主键自增的方式
    KeyGenerator keyGenerator;String keyStatementId = id + SelectKeyGenerator.SELECT_KEY_SUFFIX;keyStatementId = builderAssistant.applyCurrentNamespace(keyStatementId, true);if (configuration.hasKeyGenerator(keyStatementId)) {keyGenerator = configuration.getKeyGenerator(keyStatementId);} else {keyGenerator = context.getBooleanAttribute("useGeneratedKeys",configuration.isUseGeneratedKeys() && SqlCommandType.INSERT.equals(sqlCommandType))? Jdbc3KeyGenerator.INSTANCE : NoKeyGenerator.INSTANCE;}//通过buildAssistant将解析得到的参数设置构造成MappedStatement对象
    builderAssistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType,fetchSize, timeout, parameterMap, parameterTypeClass, resultMap, resultTypeClass,resultSetTypeEnum, flushCache, useCache, resultOrdered, keyGenerator, keyProperty, keyColumn, databaseId, langDriver, resultSets);}

将解析得到参数通过BuilderAssistant.addMappedStatement方法,解析得到MappedStatement对象。

 

上面已经说过sqlsource表示的一个SQL语句,因此我们关注langDriver.createSqlSource这个方法。看XMLLanguageDriver这个实现。

 @Overridepublic SqlSource createSqlSource(Configuration configuration, XNode script, Class<?> parameterType) {XMLScriptBuilder builder = new XMLScriptBuilder(configuration, script, parameterType);return builder.parseScriptNode();}

可以看到他将创建sqlsource的工作交给了XMLScrpitBuilder(又一个创建者模式的应用)。来看parseScriptNode方法:

public SqlSource parseScriptNode() {//解析SQL语句节点,创建MixedSqlNode对象MixedSqlNode rootSqlNode = parseDynamicTags(context);SqlSource sqlSource = null;//根据是否是动态的语句,创建DynamicSqlSource或是RawSqlSource对象,并返回if (isDynamic) {sqlSource = new DynamicSqlSource(configuration, rootSqlNode);} else {sqlSource = new RawSqlSource(configuration, rootSqlNode, parameterType);}return sqlSource;}

MixedSqlNode是SqlNode的一个实现,包含了各个子节点,用来遍历输出子节点。SqlNode还有很多不同的实现,分别对应不同的节点类型。对应关系如下:

SqlNode实现对应SQL语句中的类型
TextSqlNode${}
IfSqlNodeIf节点
TrimSqlNode/WhereSqlNode/SetSqlNodeTrim/Where/Set节点
Foreach节点foreach标签
ChooseSqlNode节点choose/when/otherwhise节点
ValDeclSqlNode节点bind节点
StaticTextSqlNode不含上述节点

 

 

 

 

 

 

除了StaticTextSqlNode节点外,其余对应的都是动态语句。

因此我们本文的关注点在StaticTextSqlNode。

让我们对应文初sql语句的解析来看一下parseDynamicTags方法,为了便于理解,我将在右边注释出每一步的结果

protected MixedSqlNode parseDynamicTags(XNode node) {// node是我们要解析的SQL语句: <select resultType="org.apache.ibatis.domain.blog.Author" id="selectAllAuthors">select * from author</select>List<SqlNode> contents = new ArrayList<SqlNode>();//获取SQL下面的子节点NodeList children = node.getNode().getChildNodes();//这里的children只有一个节点;//遍历子节点,解析成对应的sqlNode类型,并添加到contents中for (int i = 0; i < children.getLength(); i++) {XNode child = node.newXNode(children.item(i));//第一个child节点就是SQL中的文本数据:select * from author//如果是文本节点,则先解析成TextSqlNode对象if (child.getNode().getNodeType() == Node.CDATA_SECTION_NODE || child.getNode().getNodeType() == Node.TEXT_NODE) {//获取文本信息String data = child.getStringBody("");//data:select * from author//创建TextSqlNode对象TextSqlNode textSqlNode = new TextSqlNode(data);//判断是否是动态Sql,其过程会调用GenericTokenParser判断文本中是否含有"${"字符if (textSqlNode.isDynamic()) {//如果是动态SQL,则直接使用TextSqlNode类型,并将isDynamic标识置为true
          contents.add(textSqlNode);isDynamic = true;} else {//不是动态sql,则创建StaticTextSqlNode对象,表示静态SQLcontents.add(new StaticTextSqlNode(data));}} else if (child.getNode().getNodeType() == Node.ELEMENT_NODE) { //其他类型的节点,由不同的节点处理器来对应处理成本成不同的SqlNode类型String nodeName = child.getNode().getNodeName();NodeHandler handler = nodeHandlerMap.get(nodeName);if (handler == null) {throw new BuilderException("Unknown element <" + nodeName + "> in SQL statement.");}handler.handleNode(child, contents);isDynamic = true;}}//用contents构建MixedSqlNode对象return new MixedSqlNode(contents);}

上述过程中,我们主要关注静态SQL的解析过程,对于动态SQL的解析将在之后介绍。

得到MixedSqlNode后,静态的SQL会创建出RawSqlSource对象。

看一下RawSqlSource:

  public class RawSqlSource implements SqlSource {//内部封装的sqlSource对象,getBoundSql方法会委托给这个对象private final SqlSource sqlSource;public RawSqlSource(Configuration configuration, SqlNode rootSqlNode, Class<?> parameterType) {this(configuration, getSql(configuration, rootSqlNode), parameterType);}public RawSqlSource(Configuration configuration, String sql, Class<?> parameterType) {//创建sqlSourceBuilderSqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration);Class<?> clazz = parameterType == null ? Object.class : parameterType;//解析sql,创建StaticSqlSource对象sqlSource = sqlSourceParser.parse(sql, clazz, new HashMap<String, Object>());}//获取sql语句private static String getSql(Configuration configuration, SqlNode rootSqlNode) {DynamicContext context = new DynamicContext(configuration, null);//这里的rootSqlNode就是之前得到的MixedSqlNode,它会遍历内部的SqlNode,逐个调用sqlNode的apply方法。StaticTextSqlNode会直接context.appendSql方法
    rootSqlNode.apply(context);return context.getSql();}@Overridepublic BoundSql getBoundSql(Object parameterObject) {return sqlSource.getBoundSql(parameterObject);}}

代码相对简单,主要的步骤就是(1)通过SqlNode获得原始SQL语句;(2)创建SqlSourceBuilder对象,解析SQL语句,并创建StaticSqlSource对象;(3)将getBoundSql方法委托给内部的staticSqlSource对象。

其中比较关键的一步是解析原始SQL语句,并创建StaticSqlSource对象。因此我们继续看SqlSourceBuilder对象。

public class SqlSourceBuilder extends BaseBuilder {private static final String parameterProperties = "javaType,jdbcType,mode,numericScale,resultMap,typeHandler,jdbcTypeName";public SqlSourceBuilder(Configuration configuration) {super(configuration);}public SqlSource parse(String originalSql, Class<?> parameterType, Map<String, Object> additionalParameters) {//创建TokenHandler,用来将原始Sql中的'#{}' 解析成'?'ParameterMappingTokenHandler handler = new ParameterMappingTokenHandler(configuration, parameterType, additionalParameters);GenericTokenParser parser = new GenericTokenParser("#{", "}", handler);//解析原始sqlString sql = parser.parse(originalSql);//创建出StaticSqlSource对象return new StaticSqlSource(configuration, sql, handler.getParameterMappings());}private static class ParameterMappingTokenHandler extends BaseBuilder implements TokenHandler {private List<ParameterMapping> parameterMappings = new ArrayList<ParameterMapping>();private Class<?> parameterType;private MetaObject metaParameters;public ParameterMappingTokenHandler(Configuration configuration, Class<?> parameterType, Map<String, Object> additionalParameters) {super(configuration);this.parameterType = parameterType;this.metaParameters = configuration.newMetaObject(additionalParameters);}public List<ParameterMapping> getParameterMappings() {return parameterMappings;}@Overridepublic String handleToken(String content) {//解析'#{}'中的参数,创建ParameterMapping对象
      parameterMappings.add(buildParameterMapping(content));//将'#{}'替换成'?'return "?";}private ParameterMapping buildParameterMapping(String content) {Map<String, String> propertiesMap = parseParameterMapping(content);String property = propertiesMap.get("property");Class<?> propertyType;if (metaParameters.hasGetter(property)) { // issue #448 get type from additional paramspropertyType = metaParameters.getGetterType(property);} else if (typeHandlerRegistry.hasTypeHandler(parameterType)) {propertyType = parameterType;} else if (JdbcType.CURSOR.name().equals(propertiesMap.get("jdbcType"))) {propertyType = java.sql.ResultSet.class;} else if (property == null || Map.class.isAssignableFrom(parameterType)) {propertyType = Object.class;} else {MetaClass metaClass = MetaClass.forClass(parameterType, configuration.getReflectorFactory());if (metaClass.hasGetter(property)) {propertyType = metaClass.getGetterType(property);} else {propertyType = Object.class;}}ParameterMapping.Builder builder = new ParameterMapping.Builder(configuration, property, propertyType);Class<?> javaType = propertyType;String typeHandlerAlias = null;for (Map.Entry<String, String> entry : propertiesMap.entrySet()) {String name = entry.getKey();String value = entry.getValue();if ("javaType".equals(name)) {javaType = resolveClass(value);builder.javaType(javaType);} else if ("jdbcType".equals(name)) {builder.jdbcType(resolveJdbcType(value));} else if ("mode".equals(name)) {builder.mode(resolveParameterMode(value));} else if ("numericScale".equals(name)) {builder.numericScale(Integer.valueOf(value));} else if ("resultMap".equals(name)) {builder.resultMapId(value);} else if ("typeHandler".equals(name)) {typeHandlerAlias = value;} else if ("jdbcTypeName".equals(name)) {builder.jdbcTypeName(value);} else if ("property".equals(name)) {// Do Nothing} else if ("expression".equals(name)) {throw new BuilderException("Expression based parameters are not supported yet");} else {throw new BuilderException("An invalid property '" + name + "' was found in mapping #{" + content + "}.  Valid properties are " + parameterProperties);}}if (typeHandlerAlias != null) {builder.typeHandler(resolveTypeHandler(javaType, typeHandlerAlias));}return builder.build();}private Map<String, String> parseParameterMapping(String content) {try {return new ParameterExpression(content);} catch (BuilderException ex) {throw ex;} catch (Exception ex) {throw new BuilderException("Parsing error was found in mapping #{" + content + "}.  Check syntax #{property|(expression), var1=value1, var2=value2, ...} ", ex);}}}}

parse方法主要分为以下几步:

(1)创建了ParameterMappingTokenHandler对象

(2)将ParameterMappingTokenHandler对象传入GenericTokenParser的构造函数中,创建GenericTokenParser对象

(3)通过GenericTokenParser对象解析原始SQL,这个过程中会将#{}替换成?,并将#{}中的参数,解析形成ParamterMapping对象

(4)用得到的SQL和ParamterMapping对象创建StaticSqlSource对象。

 

解析完成后回到一开始的XMLMapperBuilder,它会在资源添加到已加载的列表中,并bindMapperForNamespace方法中为创建的MappedStatement添加命名空间。

转载于:https://www.cnblogs.com/insaneXs/p/9083003.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/283028.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

sealed java_Java包isSealed()方法与示例

包类isSealed()方法isSealed()方法在java.lang包中可用。isSealed()方法用于检查此程序包是否密封。isSealed()方法是一种非静态方法&#xff0c;只能通过类对象访问&#xff0c;如果尝试使用类名称访问该方法&#xff0c;则会收到错误消息。isSealed()方法在密封包装时不会引发…

java enum分析

用法一&#xff1a;常量 在JDK1.5 之前&#xff0c;我们定义常量都是&#xff1a; public static fianl.... 。现在好了&#xff0c;有了枚举&#xff0c;可以把相关的常量分组到一个枚举类型里&#xff0c;而且枚举提供了比常量更多的方法。 public enum Color { RED, GREEN,…

1176: C语言实验题――数组逆序

描述:输入10个整数存入一维数组&#xff0c;再按逆序重新存放后再输出。输入:输入包括一行。 10个以空格格开的整数输出:逆序的10个整数&#xff0c;整数以空格格开样例输入:1 3 5 9 7 6 8 2 4 0样例输出:0 4 2 8 6 7 9 5 3 1考点:数的交换代码: #include <stdio.h> int …

C# 二十年语法变迁之 C# 8参考

C# 二十年语法变迁之 C# 8参考自从 C# 于 2000 年推出以来&#xff0c;该语言的规模已经大大增加&#xff0c;我不确定任何人是否有可能在任何时候都对每一种语言特性都有深入的了解。因此&#xff0c;我想写一系列快速参考文章&#xff0c;总结自 C# 2.0 以来所有主要的新语言…

windows 提权 cve-2018-8897

windows 提权 cve-2018-8897影响范围&#xff1a;基本上是全版本具体影响范围看详情&#xff1a;https://portal.msrc.microsoft.co … isory/CVE-2018-8897http://www.o2oxy.cn/wp-content/uploads/2018/06/cve-2018-8897.rar转载于:https://blog.51cto.com/9861015/2126608

java servlet练习测试

步骤&#xff1a; 0、首先创建web project&#xff0c;工程名&#xff1a;test_servlet 1、编写Servlet&#xff0c;TestServlet.java文件内容&#xff1a; package com.ouyang.servlet;import java.io.IOException; import java.sql.Connection; import java.sql.DriverManage…

java 检测ip网速_java心跳测网速Demo

//心跳中可以放//自己瞎搞的&#xff0c;有人帮改进吗&#xff1f;package netTest;import java.io.BufferedReader;import java.io.InputStreamReader;import java.util.ArrayList;public class net_test_one {public static void main(String[] args) {try {String[] cmd ne…

简洁的 Bash Programming 技巧(三)

这是简洁的 Bash Programming 技巧系列的第三篇文章&#xff0c;这一系列的文章专门介绍 Bash 编程中一些简洁的技巧&#xff0c;帮助大家提高平时 Bash 编程的效率。有兴趣的同学可以回顾下之前的两篇文章&#xff08;一&#xff09;和续篇。 1. 替换语法${parameter/pattern/…

《ASP.NET Core 6框架揭秘》实例演示[19]:数据加解密与哈希

数据保护&#xff08;Data Protection&#xff09;框架旨在解决数据在传输与持久化存储过程中的一致性&#xff08;Integrity&#xff09;和机密性&#xff08;confidentiality&#xff09;问题&#xff0c;前者用于检验接收到的数据是否经过篡改&#xff0c;后者通过对原始的数…

java开发保险案例_Java实现双保险线程的示例代码

双保险线程&#xff0c;每次启动2个相同的线程&#xff0c;互相检测&#xff0c;避免线程死锁造成影响。两个线程都运行&#xff0c;但只有一个线程执行业务&#xff0c;但都会检测对方的时间戳 如果时间戳超过休眠时间3倍没有更新的话&#xff0c;则重新启动对方线程。例子&am…

如何在ABAP Netweaver和CloudFoundry里记录并查看日志

Netweaver 要记录日志需要有一个checkpoint group&#xff0c;可以自行创建也可以使用标准的。这里我重用标准的group&#xff1a;DEMO_CHECKPOINT_GROUP。 tcode SAAB&#xff0c;点Display <->Activate进入编辑模式&#xff0c;将Logpoints设置为"Log"&#…

TiDB 源码初探

作者: 申砾 本文档面向 TiDB 社区开发者&#xff0c;主要介绍 TiDB 的系统架构、代码结构以及执行流程。 目的是使得开发者阅读文档后&#xff0c;可以对 TiDB 项目有一个整体的了解&#xff0c;更好的参与进来。首先会介绍一下大体的结构以及 Golang 包的结构&#xff0c;然后…

C#高性能低GC 非托管动态扩容数组

开始之前相比固定长度的Array&#xff0c;大家可能在编程的时候经常会使用List<T>&#xff0c;同时可能会经常往里面Add东西&#xff0c;因为List具有可扩容性&#xff0c;但是注重GC的朋友会发现&#xff08;比如Unity开发者&#xff09;&#xff0c;List.Resize会造成扩…

leetCode 53. maximum subarray

Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1] has the largest sum 6. 贪婪算法找每个当前位置对应的最大的subar…

如何成为有效学习的高手(许岑)——思维导图

总结自许岑精品课《如何成为有效学习的高手》&#xff0c;图片看不清的可以看下面。 最后有彩蛋&#xff01;最后有彩蛋&#xff01;最后有彩蛋&#xff01; 定义 高效学习的定义&#xff1a;找到最适合自己的学习手法&#xff0c;在相对短的时间内集中注意力&#xff0c;以解决…

tomcat不能多次startup.sh,异常时直接,分析logs目录下的日志。

tomcat不能多次startup.sh&#xff0c;异常时直接干掉其进程。 分析logs目录下的日志。

java类sample是公共的_应在名samle.java的文件_Andoid NDK编程 1 - 注册native函数

打算对Android的NDK的开发做一总结&#xff0c;首先是JNI部分&#xff0c;接下来是NDK的内容。今天首先介绍一下JNI的第一部分&#xff1a;注册native函数。当java代码中执行native的代码时候&#xff0c;首先是通过一定的方法来找到这些native方法。而注册native函数的具体方法…

WPF Canvas 平滑笔迹

WPF Canvas 平滑笔迹控件名&#xff1a;CanvasHandWriting作者&#xff1a;小封&#xff08;邝攀升&#xff09;原文链接&#xff1a; https://github.com/WPFDevelopersOrg/WPFDevelopers编辑&#xff1a;驚鏵完整的思路如下收集路径点集。平均采样路径点集。将路径点集转为…

IIS应用程序池相关问题及连接池已满的解决方法

关于应用程序池 在 IIS 6.0 中,引入了应用程序池&#xff0c;应用程序池是将一个或多个应用程序链接到一个或多个工作进程集合的配置。因为应用程序池中的应用程序与其他应用程序被工作进程边界分隔&#xff0c;所以某个应用程序池中的应用程序不会受到其他应用程序池中应用程序…

echo -n 和echo -e 参数意义

echo -n 不换行输出 $echo -n "123" $echo "456" 12最终输出 123456而不是 123 456 123456echo -e 处理特殊字符 若字符串中出现以下字符&#xff0c;则特别加以处理&#xff0c;而不会将它当成一般文字输出&#xff1a; \a 发出警告声&#xff1b; \b 删…