原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9870339.html

概述

​ 我说的容器启动流程涉及两种情况,SSM开发模式和Springboot开发模式。

  SSM开发模式中,需要配置web.xml文件用作启动配置文件,而Springboot开发模式中由main方法直接启动。

  下面是web项目中容器启动的流程,起点是web.xml中配置的ContextLoaderListener监听器。

调用流程图(右键可查看大图)

流程解析

  Tomcat服务器启动时会读取项目中web.xml中的配置项来生成ServletContext,在其中注册的ContextLoaderListenerServletContextListener接口的实现类,它会时刻监听ServletContext的动作,包括创建和销毁,ServletContext创建的时候会触发其contextInitialized()初始化方法的执行。而Spring容器的初始化操作就在这个方法之中被触发。

  源码1-来自:ContextLoaderListener

  1. /**
  2. * Initialize the root web application context.
  3. */
  4. @Override
  5. public void contextInitialized(ServletContextEvent event) {
  6. initWebApplicationContext(event.getServletContext());
  7. }

  ContextLoaderListener是启动和销毁Springroot WebApplicationContext根web容器或者根web应用上下文)的引导器,其中实现了ServletContextListenercontextInitialized容器初始化方法与contextDestoryed销毁方法,用于引导根web容器的创建和销毁。

  上面方法中contextInitialized就是初始化根web容器的方法。其中调用了initWebApplicationContext方法进行Spring web容器的具体创建。

  源码2-来自:ContextLoader

  1. public WebApplicationContext initWebApplicationContext(ServletContext servletContext) {
  2. //SpringIOC容器的重复性创建校验
  3. if (servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != null) {
  4. throw new IllegalStateException(
  5. "Cannot initialize context because there is already a root application context present - " +
  6. "check whether you have multiple ContextLoader* definitions in your web.xml!");
  7. }
  8. Log logger = LogFactory.getLog(ContextLoader.class);
  9. servletContext.log("Initializing Spring root WebApplicationContext");
  10. if (logger.isInfoEnabled()) {
  11. logger.info("Root WebApplicationContext: initialization started");
  12. }
  13. //记录Spring容器创建开始时间
  14. long startTime = System.currentTimeMillis();
  15. try {
  16. // Store context in local instance variable, to guarantee that
  17. // it is available on ServletContext shutdown.
  18. if (this.context == null) {
  19. //创建Spring容器实例
  20. this.context = createWebApplicationContext(servletContext);
  21. }
  22. if (this.context instanceof ConfigurableWebApplicationContext) {
  23. ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) this.context;
  24. if (!cwac.isActive()) {
  25. //容器只有被刷新至少一次之后才是处于active(激活)状态
  26. if (cwac.getParent() == null) {
  27. //此处是一个空方法,返回null,也就是不设置父级容器
  28. ApplicationContext parent = loadParentContext(servletContext);
  29. cwac.setParent(parent);
  30. }
  31. //重点操作:配置并刷新容器
  32. configureAndRefreshWebApplicationContext(cwac, servletContext);
  33. }
  34. }
  35. //将创建完整的Spring容器作为一条属性添加到Servlet容器中
  36. servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context);
  37. ClassLoader ccl = Thread.currentThread().getContextClassLoader();
  38. if (ccl == ContextLoader.class.getClassLoader()) {
  39. //如果当前线程的类加载器是ContextLoader类的类加载器的话,也就是说如果是当前线程加载了ContextLoader类的话,则将Spring容器在ContextLoader实例中保留一份引用
  40. currentContext = this.context;
  41. }
  42. else if (ccl != null) {
  43. //添加一条ClassLoader到Springweb容器的映射
  44. currentContextPerThread.put(ccl, this.context);
  45. }
  46. if (logger.isDebugEnabled()) {
  47. logger.debug("Published root WebApplicationContext as ServletContext attribute with name [" +
  48. WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE + "]");
  49. }
  50. if (logger.isInfoEnabled()) {
  51. long elapsedTime = System.currentTimeMillis() - startTime;
  52. logger.info("Root WebApplicationContext: initialization completed in " + elapsedTime + " ms");
  53. }
  54. return this.context;
  55. }
  56. catch (RuntimeException ex) {
  57. logger.error("Context initialization failed", ex);
  58. servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);
  59. throw ex;
  60. }
  61. catch (Error err) {
  62. logger.error("Context initialization failed", err);
  63. servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, err);
  64. throw err;
  65. }
  66. }

  这里十分明了的显示出了ServletContextSpring root ApplicationContext的关系:后者只是前者的一个属性,前者包含后者。

知识点:

ServletContext表示的是一整个应用,其中囊括应用的所有内容,而Spring只是应用所采用的一种框架。从ServletContext的角度来看,Spring其实也算是应用的一部分,属于和我们编写的代码同级的存在,只是相对于我们编码人员来说,Spring是作为一种即存的编码架构而存在的,即我们将其看作我们编码的基础,或者看作应用的基础部件。虽然是基础部件,但也是属于应用的一部分。所以将其设置到ServletContext中,而且是作为一个单一属性而存在,但是它的作用却是很大的。

  源码中WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE的值为:WebApplicationContext.class.getName() + ".ROOT",这个正是Spring容器Servlet容器中的属性名。

  在这段源码中主要是概述Spring容器的创建和初始化,分别由两个方法实现:createWebApplicationContext方法和configureAndRefreshWebApplicationContext方法。

  首先,我们需要创建Spring容器,我们需要决定使用哪个容器实现。

  源码3-来自:ContextLoader

  1. protected WebApplicationContext createWebApplicationContext(ServletContext sc) {
  2. //决定使用哪个容器实现
  3. Class<?> contextClass = determineContextClass(sc);
  4. if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) {
  5. throw new ApplicationContextException("Custom context class [" + contextClass.getName() +
  6. "] is not of type [" + ConfigurableWebApplicationContext.class.getName() + "]");
  7. }
  8. //反射方式创建容器实例
  9. return (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);
  10. }
  1. //我们在web.xml中以 <context-param> 的形式设置contextclass参数来指定使用哪个容器实现类,
  2. //若未指定则使用默认的XmlWebApplicationContext,其实这个默认的容器实现也是预先配置在一个
  3. //叫ContextLoader.properties文件中的
  4. protected Class<?> determineContextClass(ServletContext servletContext) {
  5. //获取Servlet容器中配置的系统参数contextClass的值,如果未设置则为null
  6. String contextClassName = servletContext.getInitParameter(CONTEXT_CLASS_PARAM);
  7. if (contextClassName != null) {
  8. try {
  9. return ClassUtils.forName(contextClassName, ClassUtils.getDefaultClassLoader());
  10. }
  11. catch (ClassNotFoundException ex) {
  12. throw new ApplicationContextException(
  13. "Failed to load custom context class [" + contextClassName + "]", ex);
  14. }
  15. }
  16. else {
  17. //获取预先配置的容器实现类
  18. contextClassName = defaultStrategies.getProperty(WebApplicationContext.class.getName());
  19. try {
  20. return ClassUtils.forName(contextClassName, ContextLoader.class.getClassLoader());
  21. }
  22. catch (ClassNotFoundException ex) {
  23. throw new ApplicationContextException(
  24. "Failed to load default context class [" + contextClassName + "]", ex);
  25. }
  26. }
  27. }

  BeanUtilsSpring封装的反射实现,instantiateClass方法用于实例化指定类。

  我们可以在web.xml中以<context-param>的形式设置contextclass参数手动决定应用使用哪种Spring容器,但是一般情况下我们都遵循Spring的默认约定,使用ContextLoader.properties中配置的org.springframework.web.context.WebApplicationContext的值来作为默认的Spring容器来创建。

  源码4-来自:ContextLoader.properties

  1. # Default WebApplicationContext implementation class for ContextLoader.
  2. # Used as fallback when no explicit context implementation has been specified as context-param.
  3. # Not meant to be customized by application developers.
  4. org.springframework.web.context.WebApplicationContext=org.springframework.web.context.support.XmlWebApplicationContext

  可见,一般基于Springweb应用默认使用的都是XmlWebApplicationContext作为容器实现类的。

​ 下面我们来看看XmlWebApplicationContext容器实例的创建过程:

​ 首先在XmlWebApplicationContext中并没有自定义的构造器,反射工具调用的也是默认的无参构造器,让我们在看看其继承体系中有哪些初始化逻辑:

​ 首先来到AbstractRefreshableWebApplicationContext类中,其中有无参构造器逻辑:

​ 源码5-来自:AbstractRefreshableWebApplicationContext

  1. public AbstractRefreshableWebApplicationContext() {
  2. setDisplayName("Root WebApplicationContext");
  3. }

​ 可见在AbstractRefreshableWebApplicationContext中设置了容器的显示名称displayName。

​ 然后就来到AbstractApplicationContext类中,其中有无参与带参构造器逻辑:

​ 源码6-来自:AbstractApplicationContext

  1. public AbstractApplicationContext() {
  2. this(null);
  3. }
  4. public AbstractApplicationContext(ApplicationContext parent) {
  5. this.parent = parent;
  6. this.resourcePatternResolver = getResourcePatternResolver();
  7. this.environment = this.createEnvironment();
  8. }
  9. protected ResourcePatternResolver getResourcePatternResolver() {
  10. return new PathMatchingResourcePatternResolver(this);
  11. }
  12. protected ConfigurableEnvironment createEnvironment() {
  13. return new StandardEnvironment();
  14. }

​ 源码7-来自:AbstractRefreshableWebApplicationContext

  1. @Override
  2. protected ConfigurableEnvironment createEnvironment() {
  3. return new StandardServletEnvironment();
  4. }

​ 可见在无参构造器中调用了带参的构造器,主要逻辑在带参构造器中,主要包括:

  • 配置父级容器,此处传null,表示当前容器即为终极(root)容器;
  • 配置resourcePatternResolver,资源模式解析器,其实就是针对classpath*:之类的待匹配符的资源配置的解析器,这里创建了PathMatchingResourcePatternResolver解析器实例。
  • 创配置environment环境,虽然在AbstractApplicationContext中创建了StandardEnvironment实例,但是在AbstractRefreshableWebApplicationContext中重写了createEnvironment方法,所以容器持有的environment最终为StandardServletEnvironment实例。

StandardServletEnvironment实例的创建也要执行一定的初始化,这些逻辑位于AbstractEnvironment类中:

​ 源码8-来自:AbstractEnvironment

  1. public AbstractEnvironment() {
  2. String name = this.getClass().getSimpleName();
  3. if (this.logger.isDebugEnabled()) {
  4. this.logger.debug(format("Initializing new %s", name));
  5. }
  6. this.customizePropertySources(this.propertySources);
  7. if (this.logger.isDebugEnabled()) {
  8. this.logger.debug(format(
  9. "Initialized %s with PropertySources %s", name, this.propertySources));
  10. }
  11. }
  12. protected void customizePropertySources(MutablePropertySources propertySources) {
  13. }

​ 初始化的主要逻辑在customizePropertySources方法,当前类中的该方法是无逻辑的,会执行子类中重写的逻辑:

​ 源码9-来自:StandardServletEnvironment

  1. @Override
  2. protected void customizePropertySources(MutablePropertySources propertySources) {
  3. propertySources.addLast(new StubPropertySource(SERVLET_CONFIG_PROPERTY_SOURCE_NAME));
  4. propertySources.addLast(new StubPropertySource(SERVLET_CONTEXT_PROPERTY_SOURCE_NAME));
  5. if (JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()) {
  6. propertySources.addLast(new JndiPropertySource(JNDI_PROPERTY_SOURCE_NAME));
  7. }
  8. super.customizePropertySources(propertySources);
  9. }

​ 源码10-来自:StandardEnvironment

  1. @Override
  2. protected void customizePropertySources(MutablePropertySources propertySources) {
  3. propertySources.addLast(new MapPropertySource(SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, getSystemProperties()));
  4. propertySources.addLast(new SystemEnvironmentPropertySource(SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, getSystemEnvironment()));
  5. }

​ 上面就是所有在环境初始化式执行的逻辑了,为了后面的内容阅读,有必要了解以下内容:PropertySource,PropertySources,MutablePropertySources,StubPropertySource等的作用。

  • PropertySource:用于封装一个键值对形式的properties属性配置文件的属性资源模型

  • PropertySources:继承自Iterable<PropertySource<?>>,表示的是一个或者多个PropertySource资源模型的综合模型

  • MutablePropertySources:实现了PropertySources接口,表示的就是多个PropertySource资源模型,其内部封装了一个链表集合propertySourceList,用于存放多个PropertySource资源模型。

    1. private final LinkedList<PropertySource<?>> propertySourceList = new LinkedList<PropertySource<?>>();
  • StubPropertySource:继承自PropertySource,并不表示某一具体的资源模型,而是表示一个资源占位,当在Spring容器创建的时候,实际的资源无法被快速初始化的情况下,可以先用该类的实例进行占位,等到容器刷新的时候执行实际属性资源的替换操作。

​ 初步了解了这四个内容之后,我们就来详细看看环境的初始化做了哪些工作?其实很简单,就是将一些配置信息添加到环境所持有的MutablePropertySources实例中的propertySourceList链表中备用,主要看看添加了那些配置信息:

  • web.xml中配置的servletContextInitParams初始化参数值

  • web.xml中配置的servletConfigInitParams初始化参数值

  • jndi配置信息jndiProperties,只有在这个JVM上有默认的JNDI环境(如Java EE环境)的情况下才会配置。

  • 操作系统的属性:systemProperties

  • 操作系统的环境属性:systemEnvironment

    将以上内容按顺序添加到链表中备用之后,StandardServletEnvironment初始化完毕。

  到此位置容器实例就创建好了,下一步就是配置和刷新了。

  源码11-来自:ContextLoader

  1. protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac, ServletContext sc) {
  2. if (ObjectUtils.identityToString(wac).equals(wac.getId())) {
  3. // The application context id is still set to its original default value
  4. // -> assign a more useful id based on available information
  5. String idParam = sc.getInitParameter(CONTEXT_ID_PARAM);
  6. if (idParam != null) {
  7. wac.setId(idParam);
  8. }
  9. else {
  10. // Generate default id...
  11. wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
  12. ObjectUtils.getDisplayString(sc.getContextPath()));
  13. }
  14. }
  15. //在当前Spring容器中保留对Servlet容器的引用
  16. wac.setServletContext(sc);
  17. //设置web.xml中配置的contextConfigLocation参数值到当前容器中
  18. String configLocationParam = sc.getInitParameter(CONFIG_LOCATION_PARAM);
  19. if (configLocationParam != null) {
  20. wac.setConfigLocation(configLocationParam);
  21. }
  22. // The wac environment's #initPropertySources will be called in any case when the context
  23. // is refreshed; do it eagerly here to ensure servlet property sources are in place for
  24. // use in any post-processing or initialization that occurs below prior to #refresh
  25. //在容器刷新之前,提前进行属性资源的初始化,以备使用,将ServletContext设置为servletContextInitParams
  26. ConfigurableEnvironment env = wac.getEnvironment();
  27. if (env instanceof ConfigurableWebEnvironment) {
  28. ((ConfigurableWebEnvironment) env).initPropertySources(sc, null);
  29. }
  30. //取得web.xml中配置的contextInitializerClasses和globalInitializerClasses对应的初始化器,并执行初始化操作,需自定义初始化器
  31. customizeContext(sc, wac);
  32. //刷新容器
  33. wac.refresh();
  34. }

  首先将ServletContext的引用置入Spring容器中,以便可以方便的访问ServletContext;然后从ServletContext中找到contextConfigLocation参数的值,配置是在web.xml中以<context-param>形式配置的。

知识点:

​ 在Spring中凡是以<context-param>配置的内容都会在web.xml加载的时候优先存储到ServletContext之中,我们可以将其看成ServletContext的配置参数,将参数配置到ServletContext中后,我们就能方便的获取使用了,就如此处我们就能直接从ServletContext中获取contextConfigLocation的值,用于初始化Spring容器

  在Javaweb开发中,尤其是使用Spring辅助开发的情况下,基本就是一个容器对应一套配置,这套配置就是用于初始化容器的。ServletContext对应于<context-param>配置,Spring容器对应applicationContext.xml配置,这个配置属于默认的配置,如果自定义名称就需要将其配置到<context-param>中备用了,还有DispatchServletSpring容器对应spring-mvc.xml配置文件。

  Spring容器environment表示的是容器运行的基础环境配置,其中保存的是ProfileProperties,其initPropertySources方法是在ConfigurableWebEnvironment接口中定义的,是专门用于web应用中来执行真实属性资源与占位符资源(StubPropertySource)的替换操作的。

​ 源码12-来自:StandardServletEnvironment

  1. @Override
  2. public void initPropertySources(@Nullable ServletContext servletContext, @Nullable ServletConfig servletConfig) {
  3. WebApplicationContextUtils.initServletPropertySources(getPropertySources(), servletContext, servletConfig);
  4. }

​ 源码13-来自:WebApplicationContextUtils

  1. public static void initServletPropertySources(MutablePropertySources sources,
  2. @Nullable ServletContext servletContext, @Nullable ServletConfig servletConfig) {
  3. Assert.notNull(sources, "'propertySources' must not be null");
  4. String name = StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME;
  5. if (servletContext != null && sources.contains(name) && sources.get(name) instanceof StubPropertySource) {
  6. sources.replace(name, new ServletContextPropertySource(name, servletContext));
  7. }
  8. name = StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME;
  9. if (servletConfig != null && sources.contains(name) && sources.get(name) instanceof StubPropertySource) {
  10. sources.replace(name, new ServletConfigPropertySource(name, servletConfig));
  11. }
  12. }

​ 从上面的源码中可以看出,这里只进行了有关Servlet的占位资源的替换操作:ServletContext和ServletConfig。

  上面源码中customizeContext方法的目的是在刷新容器之前对容器进行自定义的初始化操作,需要我们实现ApplicationContextInitializer<C extends ConfigurableApplicationContext>接口,然后将其配置到web.xml中即可生效。

  源码14-来自:ContextLoader

  1. protected void customizeContext(ServletContext sc, ConfigurableWebApplicationContext wac) {
  2. //获取初始化器类集合
  3. List<Class<ApplicationContextInitializer<ConfigurableApplicationContext>>> initializerClasses =
  4. determineContextInitializerClasses(sc);
  5. for (Class<ApplicationContextInitializer<ConfigurableApplicationContext>> initializerClass : initializerClasses) {
  6. Class<?> initializerContextClass =
  7. GenericTypeResolver.resolveTypeArgument(initializerClass, ApplicationContextInitializer.class);
  8. if (initializerContextClass != null && !initializerContextClass.isInstance(wac)) {
  9. throw new ApplicationContextException(String.format(
  10. "Could not apply context initializer [%s] since its generic parameter [%s] " +
  11. "is not assignable from the type of application context used by this " +
  12. "context loader: [%s]", initializerClass.getName(), initializerContextClass.getName(),
  13. wac.getClass().getName()));
  14. }
  15. //实例化初始化器并添加到集合中
  16. this.contextInitializers.add(BeanUtils.instantiateClass(initializerClass));
  17. }
  18. //排序并执行,编号越小越早执行
  19. AnnotationAwareOrderComparator.sort(this.contextInitializers);
  20. for (ApplicationContextInitializer<ConfigurableApplicationContext> initializer : this.contextInitializers) {
  21. initializer.initialize(wac);
  22. }
  23. }
  1. protected List<Class<ApplicationContextInitializer<ConfigurableApplicationContext>>>
  2. determineContextInitializerClasses(ServletContext servletContext) {
  3. List<Class<ApplicationContextInitializer<ConfigurableApplicationContext>>> classes =
  4. new ArrayList<Class<ApplicationContextInitializer<ConfigurableApplicationContext>>>();
  5. //通过<context-param>属性配置globalInitializerClasses获取全局初始化类名
  6. String globalClassNames = servletContext.getInitParameter(GLOBAL_INITIALIZER_CLASSES_PARAM);
  7. if (globalClassNames != null) {
  8. for (String className : StringUtils.tokenizeToStringArray(globalClassNames, INIT_PARAM_DELIMITERS)) {
  9. classes.add(loadInitializerClass(className));
  10. }
  11. }
  12. //通过<context-param>属性配置contextInitializerClasses获取容器初始化类名
  13. String localClassNames = servletContext.getInitParameter(CONTEXT_INITIALIZER_CLASSES_PARAM);
  14. if (localClassNames != null) {
  15. for (String className : StringUtils.tokenizeToStringArray(localClassNames, INIT_PARAM_DELIMITERS)) {
  16. classes.add(loadInitializerClass(className));
  17. }
  18. }
  19. return classes;
  20. }

  initPropertySources操作用于配置属性资源,其实在refresh操作中也会执行该操作,这里提前执行,目的为何,暂未可知。

  到达refresh操作我们先暂停。refresh操作是容器初始化的操作。是通用操作,而到达该点的方式确实有多种,每种就是一种Spring的开发方式。

  除了此处的web开发方式,还有Springboot开发方式,貌似就两种。。。下面说说Springboot启动的流程,最后统一说refresh流程。

Spring基础系列-容器启动流程(1)的更多相关文章

  1. Spring基础系列-容器启动流程(2)

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9503210.html 一.概述 这里是Springboot项目启动大概流程,区别于SSM ...

  2. Spring基础系列-AOP源码分析

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9560803.html 一.概述 Spring的两大特性:IOC和AOP. AOP是面向切 ...

  3. Spring基础系列--AOP织入逻辑跟踪

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9619910.html 其实在之前的源码解读里面,关于织入的部分并没有说清楚,那些前置.后 ...

  4. Spring基础系列-Spring事务不生效的问题与循环依赖问题

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9476550.html 一.提出问题 不知道你是否遇到过这样的情况,在ssm框架中开发we ...

  5. Spring基础系列-Web开发

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9996902.html SpringBoot基础系列-web开发 概述 web开发就是集成 ...

  6. spring boot, 容器启动后执行某操作

    常有在spring容器启动后执行某些操作的需求,现做了一个demo的实现,做一下记录,也希望可以给需要的同学提供参考. 1.spring启动后,以新线程执行后续需要的操作,所以执行类实现Runnabl ...

  7. Spring Boot 应用程序启动流程分析

    SpringBoot 有两个关键元素: @SpringBootApplicationSpringApplication 以及 run() 方法 SpringApplication 这个类应该算是 Sp ...

  8. SpringBean容器启动流程+Bean的生命周期【附源码】

    如果对SpringIoc与Aop的源码感兴趣,可以访问参考:https://javadoop.com/,十分详细. 目录 Spring容器的启动全流程 Spring容器关闭流程 Bean 的生命周期 ...

  9. dubbo源码学习(一)dubbo容器启动流程简略分析

    最近在学习dubbo,dubbo的使用感觉非常的简单,方便,基于Spring的容器加载配置文件就能直接搭建起dubbo,之前学习中没有养成记笔记的习惯,时间一久就容易忘记,后期的复习又需要话费较长的时 ...

随机推荐

  1. 马昕璐 201771010118《面向对象程序设计(java)》第十六周学习总结

    第一部分:理论知识学习部分 程序:一段静态的代码,应用程序执行的蓝本. 进程:是程序的一次动态执行,它对应了从代码加载.执行至执行完毕的一个完整过程. 多线程:进程执行过程中产生的多条执行线索,比进程 ...

  2. Python 版本管理anaconda

    下载安装 下载地址 :anaconda官网 下载后直接命令行安装,默认安装按enter 和yes bash Anaconda3-5.2.0-Linux-x86_64.sh 按照官网上下一步直接用con ...

  3. Python函数式编程之闭包

    -------------------------函数式编程之*******闭包------------------------ Note: 一:简介 函数式编程不是程序必须要的,但是对于简化程序有很 ...

  4. python语法_模块_os_sys

    os模块:提供对此操作系统进行操作的接口 os.getcwd() 获取python运行的工作目录. os.chdir(r'C:\USERs') 修改当前工作目录. os.curdir 返回当前目录 ( ...

  5. 理解Golang哈希表Map的元素

    目录 概述 哈希函数 冲突解决 初始化 结构体 字面量 运行时 操作 访问 写入 扩容 删除 总结 在上一节中我们介绍了 数组和切片的实现原理,这一节会介绍 Golang 中的另一个集合元素 - 哈希 ...

  6. [Swift]LeetCode1029. 两地调度 | Two City Scheduling

    There are 2N people a company is planning to interview. The cost of flying the i-th person to city A ...

  7. zookeeper使用详解(命令、客户端、源码)

    1. zookeeper使用详解(命令.客户端.源码) 1.1. 前言   zookeeper我们常用来做分布式协调中间件,很多时候我们都接触不到它的原理和用法,我对他的了解也仅限于知道它可以做分布式 ...

  8. PowerShell 中 RunspacePool 执行异步多线程任务

    在 PowerShell 中要执行任务脚本,现在通常使用 Runspace,效率很高:任务比较多时,用 Runspace pool 来执行异步操作,可以控制资源池数量,就像 C# 中的线程池一样 == ...

  9. 我们为什么要搞长沙.NET技术社区?

    我们为什么要搞长沙.NET技术社区? 感谢大家的关注,请允许我冒昧的向大家汇报长沙.NET技术社区第一次交流会的会议进展情况. 活动过程汇报 2019年2月17日,继深圳,广州,西安,成都,苏州相继成 ...

  10. Mac下 .bash_profile 和 .zshrc 两者之间的区别

    这是我碰到的需要 source 之后才能使用环境变量的问题,我就不细究了,说说我的看法. .bash_profile 中修改环境变量只对当前窗口有效,而且需要 source ~/.bash_profi ...