<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Interview Questions on LOCRIAN_V Blog</title>
    <link>https://lv-blog.pages.dev/en/tags/interview-questions/</link>
    <description>Recent content in Interview Questions on LOCRIAN_V Blog</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Sun, 23 Mar 2025 13:21:54 +0800</lastBuildDate>
    <atom:link href="https://lv-blog.pages.dev/en/tags/interview-questions/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Message Middleware: Interview Questions</title>
      <link>https://lv-blog.pages.dev/en/posts/programming/for-interview/mq-interview-questions/</link>
      <pubDate>Sun, 23 Mar 2025 13:21:54 +0800</pubDate>
      <guid>https://lv-blog.pages.dev/en/posts/programming/for-interview/mq-interview-questions/</guid>
      <description>&lt;h1 id=&#34;rabbitmq&#34;&gt;RabbitMQ&lt;/h1&gt;
&lt;h2 id=&#34;how-does-rabbitmq-guarantee-messages-are-not-lost&#34;&gt;How does RabbitMQ guarantee messages are not lost?&lt;/h2&gt;
&lt;!-- TODO review --&gt;
&lt;ul&gt;
&lt;li&gt;Where can loss happen
&lt;ul&gt;
&lt;li&gt;publisher -&amp;gt; exchange
&lt;ul&gt;
&lt;li&gt;Producer confirmation mechanism
&lt;ul&gt;
&lt;li&gt;ack publish-confirm&lt;/li&gt;
&lt;li&gt;nack publish-confirm&lt;/li&gt;
&lt;li&gt;ack publish-return&lt;/li&gt;
&lt;li&gt;How to handle a failed message
&lt;ul&gt;
&lt;li&gt;Callback method&lt;/li&gt;
&lt;li&gt;Log it&lt;/li&gt;
&lt;li&gt;Save to the database and resend on a schedule&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;exchange -&amp;gt; queue
&lt;ul&gt;
&lt;li&gt;Message persistence
&lt;ul&gt;
&lt;li&gt;Exchange persistence&lt;/li&gt;
&lt;li&gt;Queue persistence&lt;/li&gt;
&lt;li&gt;Message persistence&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;queue&lt;/li&gt;
&lt;li&gt;queue -&amp;gt; consumer
&lt;ul&gt;
&lt;li&gt;Consumer acknowledgment mechanism&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;how-is-the-duplicate-consumption-problem-in-rabbitmq-solved&#34;&gt;How is the duplicate-consumption problem in RabbitMQ solved?&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Causes of duplicate consumption&lt;/strong&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Spring Cloud: Interview Questions</title>
      <link>https://lv-blog.pages.dev/en/posts/programming/for-interview/spring-cloud-interview-questions/</link>
      <pubDate>Sun, 23 Feb 2025 13:20:18 +0800</pubDate>
      <guid>https://lv-blog.pages.dev/en/posts/programming/for-interview/spring-cloud-interview-questions/</guid>
      <description>&lt;h2 id=&#34;the-openfeign-service-call-process&#34;&gt;The OpenFeign service-call process&lt;/h2&gt;
&lt;pre class=&#34;mermaid&#34;&gt;flowchart TD

A[&#34;Business code calls&lt;br/&gt;userClient.getById(1L)&#34;] --&gt; B[&#34;JDK dynamic proxy Proxy.invoke&#34;]

B --&gt; C[&#34;Feign InvocationHandler&lt;br/&gt;MethodHandler&#34;]

C --&gt; D[&#34;Contract parses annotations&lt;br/&gt;@GetMapping / @PathVariable&#34;]

D --&gt; E[&#34;RequestTemplate builds the HTTP request&#34;]

E --&gt; F[&#34;Parameter binding&lt;br/&gt;Path / Query / Body / Header&#34;]

F --&gt; G[&#34;Service name resolution: user-service&#34;]

G --&gt; H[&#34;Service discovery: Nacos / Eureka&#34;]

H --&gt; I[&#34;LoadBalancer load balancing&#34;]

I --&gt; J[&#34;Select instance IP:PORT&#34;]

J --&gt; K[&#34;HTTP Client executor&lt;br/&gt;OkHttp / Apache / JDK&#34;]

K --&gt; L[&#34;Send HTTP request GET /user/1&#34;]

L --&gt; M[&#34;Remote service: user-service&#34;]

M --&gt; N[&#34;Controller handles the request&#34;]

N --&gt; O[&#34;Return JSON&#34;]

O --&gt; P[&#34;Feign Decoder deserializes&#34;]

P --&gt; Q[&#34;JSON → UserDTO&#34;]

Q --&gt; R[&#34;Return to business code&#34;]
&lt;/pre&gt;</description>
    </item>
    <item>
      <title>Spring: Interview Questions</title>
      <link>https://lv-blog.pages.dev/en/posts/programming/for-interview/spring-interview-questions/</link>
      <pubDate>Sat, 19 Oct 2024 23:19:24 +0800</pubDate>
      <guid>https://lv-blog.pages.dev/en/posts/programming/for-interview/spring-interview-questions/</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;These interview questions were collected from every corner of the internet&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&#34;talk-about-the-underlying-implementation-of-spring-ioc&#34;&gt;Talk about the underlying implementation of Spring IOC&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Reflection&lt;/li&gt;
&lt;li&gt;The value of the factory&lt;/li&gt;
&lt;li&gt;Design patterns&lt;/li&gt;
&lt;li&gt;A few key methods
&lt;ul&gt;
&lt;li&gt;createBeanFactory&lt;/li&gt;
&lt;li&gt;getBean&lt;/li&gt;
&lt;li&gt;doGetBean&lt;/li&gt;
&lt;li&gt;createBean&lt;/li&gt;
&lt;li&gt;doCreateBean&lt;/li&gt;
&lt;li&gt;createBeanInstance(getDeclaredConstructor, newInstance)&lt;/li&gt;
&lt;li&gt;populateBean&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&#34;mermaid&#34;&gt;flowchart TD
    A[Start] --&gt; B[&#34;createBeanFactory()&lt;br/&gt;create DefaultListableBeanFactory&#34;]
    B --&gt; C[Load BeanDefinitions&lt;br/&gt;parse XML/annotations]
    C --&gt; D[&#34;getBean(beanName)&lt;br/&gt;external call entry&#34;]

    D --&gt; E[&#34;doGetBean(beanName)&#34;]
    E --&gt; F{Get singleton from cache?}
    F --&gt;|Yes| G[Return the cached Bean]
    F --&gt;|No| H[&#34;createBean(beanName, mbd)&#34;]

    H --&gt; I[&#34;doCreateBean(beanName, mbd)&#34;]
    I --&gt; J[&#34;createBeanInstance()&lt;br/&gt;getDeclaredConstructor + newInstance&#34;]
    J --&gt; K[&#34;populateBean()&lt;br/&gt;property filling / dependency injection&#34;]
    K --&gt; L[&#34;initializeBean()&lt;br/&gt;initialization callbacks&#34;]
    L --&gt; M[Register destroy methods]
    M --&gt; N[Return the complete Bean instance]
&lt;/pre&gt;
&lt;h2 id=&#34;talk-about-your-understanding-of-spring-ioc--its-principle-and-implementation&#34;&gt;Talk about your understanding of Spring IOC — its principle and implementation&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;The IOC idea&lt;/li&gt;
&lt;li&gt;DI as the means of implementation&lt;/li&gt;
&lt;li&gt;What is a container, what is a Bean&lt;/li&gt;
&lt;li&gt;BeanDefinition
&lt;ul&gt;
&lt;li&gt;Where it&amp;rsquo;s read from
&lt;ul&gt;
&lt;li&gt;XML&lt;/li&gt;
&lt;li&gt;Annotations&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Where it&amp;rsquo;s stored
&lt;ul&gt;
&lt;li&gt;All BeanDefinitions are stored in a Map inside DefaultListableBeanFactory&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;the-container-lifecycle&#34;&gt;The container lifecycle&lt;/h2&gt;
&lt;pre class=&#34;mermaid&#34;&gt;flowchart TD
    START([🚀 Program starts]) --&gt; REFRESH[&#34;AbstractApplicationContext.refresh()&#34;]

    REFRESH --&gt; PHASE1

    subgraph PHASE1[&#34;🔵 Phase 1: Preparation&#34;]
        direction TB
        A1[&#34;prepareRefresh()\nrecord start time\nset container state to &#39;active&#39;\ninitialize environment variables&#34;] --&gt; A2
        A2[&#34;obtainFreshBeanFactory()\ncreate DefaultListableBeanFactory\nthe container&#39;s core repository&#34;] --&gt; A3
        A3[&#34;prepareBeanFactory()\nregister basic BeanPostProcessors\nregister Aware-related processors\nregister the default environment Bean&#34;]
    end

    PHASE1 --&gt; PHASE2

    subgraph PHASE2[&#34;🟢 Phase 2: Load BeanDefinitions (read the blueprints)&#34;]
        direction TB
        B1[&#34;scan the packages specified by @ComponentScan\nor read the XML config file&#34;] --&gt; B2
        B2[&#34;parse annotations / XML\nrecognize @Component @Service\n@Repository @Controller @Bean&#34;] --&gt; B3
        B3[&#34;generate a BeanDefinition for each Bean\nrecord: class name, scope, lazy or not\ninit method, destroy method, dependencies&#34;] --&gt; B4
        B4[(&#34;store into beanDefinitionMap\nkey = beanName\nvalue = BeanDefinition&#34;)]
    end

    PHASE2 --&gt; PHASE3

    subgraph PHASE3[&#34;🟡 Phase 3: Modify BeanDefinitions (edit the blueprints)&#34;]
        direction TB
        C1[&#34;invokeBeanFactoryPostProcessors()\nrun all BeanFactoryPostProcessors&#34;] --&gt; C2
        C2[&#34;ConfigurationClassPostProcessor\nhandle @Configuration @Import\n@PropertySource @ComponentScan\n👉 Spring Boot auto-configuration triggers here&#34;] --&gt; C3
        C3[&#34;PropertySourcesPlaceholderConfigurer\nreplace all ${xxx} placeholders in\nBeanDefinitions with real values&#34;] --&gt; C4
        C4[/&#34;all BeanDefinitions finalized\nthe blueprints no longer change&#34;/]
    end

    PHASE3 --&gt; PHASE4

    subgraph PHASE4[&#34;🌸 Phase 4: Register BeanPostProcessors (workers take their posts)&#34;]
        direction TB
        D1[&#34;registerBeanPostProcessors()\nregister by priority\nPriorityOrdered → Ordered → ordinary&#34;] --&gt; D2
        D2[&#34;AutowiredAnnotationBeanPostProcessor\nhandles @Autowired @Value&#34;] --&gt; D3
        D3[&#34;CommonAnnotationBeanPostProcessor\nhandles @PostConstruct @PreDestroy @Resource&#34;] --&gt; D4
        D4[&#34;AnnotationAwareAspectJAutoProxyCreator\ndetects aspects, generates AOP proxies&#34;] --&gt; D5
        D5[/&#34;all workers in place\nwaiting to intervene during Bean creation\nnot working yet&#34;/]
    end

    PHASE4 --&gt; PHASE5

    subgraph PHASE5[&#34;🟣 Phase 5: Initialize container infrastructure&#34;]
        direction TB
        E1[&#34;initMessageSource()\ninitialize i18n resources&#34;] --&gt; E2
        E2[&#34;initApplicationEventMulticaster()\ninitialize the event multicaster&#34;] --&gt; E3
        E3[&#34;onRefresh()\n⭐ Spring Boot starts here\nTomcat / Jetty / Undertow\nthe web container begins listening on a port&#34;] --&gt; E4
        E4[&#34;registerListeners()\nregister all ApplicationListeners\nlisten for container events&#34;]
    end

    PHASE5 --&gt; PHASE6

    subgraph PHASE6[&#34;🟠 Phase 6: Instantiate all singleton Beans&#34;]
        direction TB
        F1[&#34;finishBeanFactoryInitialization()\npreInstantiateSingletons()\niterate all non-lazy singleton BeanDefinitions&#34;] --&gt; F2
        F2[&#34;execute getBean() one by one\ntrigger each Bean&#39;s lifecycle\ninstantiate → fill properties → Aware callbacks\n→ pre-processing → init method → post-processing&#34;] --&gt; F3
        F3[(&#34;all singleton Beans stored in\nthe singletonObjects level-1 cache\n✅ all ready&#34;)]
    end

    PHASE6 --&gt; PHASE7

    subgraph PHASE7[&#34;✅ Phase 7: Container ready&#34;]
        direction TB
        G1[&#34;finishRefresh()\nclean up resources used at startup\ninitialize the lifecycle processor&#34;] --&gt; G2
        G2[&#34;publish ContextRefreshedEvent\nnotify all listeners: container startup complete&#34;] --&gt; G3
        G3[/&#34;container enters running state\ncan handle business requests&#34;/]
    end

    G3 --&gt; RUNNING([🎉 Container running normally])

    RUNNING -.-&gt;|&#34;receive shutdown signal\nCtrl+C / kill / close()&#34;| PHASE8

    subgraph PHASE8[&#34;🔴 Phase 8: Container destruction&#34;]
        direction TB
        H1[&#34;publish ContextClosedEvent\nnotify all listeners: container about to close&#34;] --&gt; H2
        H2[&#34;stop the web container\nTomcat stops accepting new requests&#34;] --&gt; H3
        H3[&#34;run all Beans&#39; destroy logic\n@PreDestroy → destroy() → destroy-method\ndestroy in reverse registration order&#34;] --&gt; H4
        H4[&#34;clear all caches\nsingletonObjects cleared\nbeanDefinitionMap cleared&#34;] --&gt; H5
        H5[&#34;set container state to &#39;closed&#39;\nactive = false / closed = true&#34;]
    end

    H5 --&gt; END([💀 Container destruction complete])

    style START fill:#43A047,color:#fff
    style RUNNING fill:#43A047,color:#fff
    style END fill:#e53935,color:#fff
    style REFRESH fill:#1E88E5,color:#fff
&lt;/pre&gt;
&lt;h2 id=&#34;the-bean-lifecycle&#34;&gt;The Bean lifecycle&lt;/h2&gt;
&lt;pre class=&#34;mermaid&#34;&gt;flowchart TD
    START([🌱 Start creating the Bean]) --&gt; A

    A[&#34;① Instantiation\nInstantiation\nreflectively call the constructor\nnew an empty shell object\nall fields are null at this point&#34;] --&gt; B

    B[&#34;② Put into the level-3 cache\nsingletonFactories\nexpose the half-built object early\nto prepare for circular dependencies&#34;] --&gt; C

    C[&#34;③ Property filling\npopulateBean()\nhandle @Autowired @Value\ninject the dependent Beans&#34;] --&gt; D

    subgraph AWARE[&#34;④ Aware callbacks&#34;]
        direction TB
        D[&#34;BeanNameAware\ntell the Bean its own name&#34;] --&gt; E
        E[&#34;BeanFactoryAware\npass the BeanFactory to the Bean&#34;] --&gt; F
        F[&#34;ApplicationContextAware\npass the ApplicationContext to the Bean&#34;]
    end

    subgraph INIT[&#34;⑤ Initialization initializeBean()&#34;]
        direction TB
        G[&#34;pre-processing\npostProcessBeforeInitialization()\nall BeanPostProcessors run one by one\n📌 @PostConstruct is called here&#34;] --&gt; INITMETHOD

        subgraph INITMETHOD[&#34;init methods (executed in order)&#34;]
            direction TB
            H1[&#34;1st: @PostConstruct\n(already run in pre-processing)&#34;] --&gt; H2
            H2[&#34;2nd: afterPropertiesSet()\nimplement the InitializingBean interface&#34;] --&gt; H3
            H3[&#34;3rd: init-method\n@Bean(initMethod=&#39;xxx&#39;) or XML config&#34;]
        end

        INITMETHOD --&gt; I

        I[&#34;post-processing\npostProcessAfterInitialization()\nall BeanPostProcessors run one by one\n⭐ AOP proxies are generated here&#34;]
    end

    AWARE --&gt; INIT

    I --&gt; J

    subgraph CACHE[&#34;⑥ Store into the cache&#34;]
        direction TB
        J[&#34;remove from the level-3 cache singletonFactories\nremove from the level-2 cache earlySingletonObjects&#34;] --&gt; K
        K[&#34;store into the level-1 cache singletonObjects\n✅ complete Bean ready&#34;]
    end

    K --&gt; READY([🎉 Bean is now usable])

    READY -.-&gt;|&#34;container closes&#34;| DESTROY

    subgraph DESTROY[&#34;⑦ Destruction phase (on container close)&#34;]
        direction TB
        D1[&#34;1st: @PreDestroy\nmethod is called&#34;] --&gt; D2
        D2[&#34;2nd: destroy()\nimplement the DisposableBean interface&#34;] --&gt; D3
        D3[&#34;3rd: destroy-method\n@Bean(destroyMethod=&#39;xxx&#39;) or XML config&#34;]
    end

    D3 --&gt; END([💀 Bean destruction complete])
&lt;/pre&gt;
&lt;h2 id=&#34;springs-three-level-cache-dependency-flow&#34;&gt;Spring&amp;rsquo;s three-level cache dependency flow&lt;/h2&gt;
&lt;pre class=&#34;mermaid&#34;&gt;sequenceDiagram
    participant Spring as Spring container
    participant L3 as Level-3 cache&lt;br/&gt;singletonFactories
    participant L2 as Level-2 cache&lt;br/&gt;earlySingletonObjects
    participant L1 as Level-1 cache&lt;br/&gt;singletonObjects

    Note over Spring: Start creating A

    Spring-&gt;&gt;Spring: ① new A empty-shell object
    Spring-&gt;&gt;L3: ② store A&#39;s ObjectFactory lambda

    Note over Spring: Injecting properties into A, discovers it needs B

    Spring-&gt;&gt;Spring: ③ new B empty-shell object
    Spring-&gt;&gt;L3: ④ store B&#39;s ObjectFactory lambda

    Note over Spring: Injecting properties into B, discovers it needs A

    Spring-&gt;&gt;L1: ⑤ getBean(A), check level-1 cache
    L1--&gt;&gt;Spring: ❌ not there

    Spring-&gt;&gt;L2: check level-2 cache
    L2--&gt;&gt;Spring: ❌ not there

    Spring-&gt;&gt;L3: check level-3 cache
    L3--&gt;&gt;Spring: ✅ found A&#39;s lambda!

    Spring-&gt;&gt;Spring: ⑥ execute the lambda&lt;br/&gt;(generate proxy A if a proxy is needed)
    Spring-&gt;&gt;L2: ⑦ put the early reference into the level-2 cache
    Spring-&gt;&gt;L3: remove A from the level-3 cache

    Note over Spring: B gets A&#39;s early reference, B finishes initialization

    Spring-&gt;&gt;L1: ⑧ put B into the level-1 cache ✅
    Spring-&gt;&gt;L3: remove B from the level-3 cache

    Note over Spring: Back in A&#39;s flow, B is ready, A finishes initialization

    Spring-&gt;&gt;L1: ⑨ put A into the level-1 cache ✅
    Spring-&gt;&gt;L2: remove A from the level-2 cache

    Note over L1: Finally: the level-1 cache holds complete A and B ✅
&lt;/pre&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Case&lt;/th&gt;
					&lt;th&gt;Level-3 cache&lt;/th&gt;
					&lt;th&gt;lambda executed&lt;/th&gt;
					&lt;th&gt;Level-2 cache&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;No circular dep, no AOP&lt;/td&gt;
					&lt;td&gt;stored the lambda&lt;/td&gt;
					&lt;td&gt;❌ not executed&lt;/td&gt;
					&lt;td&gt;not used&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;No circular dep, with AOP&lt;/td&gt;
					&lt;td&gt;stored the lambda&lt;/td&gt;
					&lt;td&gt;❌ not executed&lt;/td&gt;
					&lt;td&gt;not used&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Circular dep, no AOP&lt;/td&gt;
					&lt;td&gt;stored the lambda&lt;/td&gt;
					&lt;td&gt;✅ executed&lt;/td&gt;
					&lt;td&gt;stores the raw object&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Circular dep, with AOP&lt;/td&gt;
					&lt;td&gt;stored the lambda&lt;/td&gt;
					&lt;td&gt;✅ executed&lt;/td&gt;
					&lt;td&gt;stores the proxy object&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&#34;when-spring-bean-caches-are-placed-and-removed&#34;&gt;When Spring Bean caches are placed and removed&lt;/h2&gt;
&lt;h2 id=&#34;when-spring-beans-three-level-caches-are-placed-and-removed&#34;&gt;When Spring Bean&amp;rsquo;s three-level caches are placed and removed&lt;/h2&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Cache&lt;/th&gt;
					&lt;th&gt;What it stores&lt;/th&gt;
					&lt;th&gt;When placed&lt;/th&gt;
					&lt;th&gt;When removed&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;Level-3 &lt;code&gt;singletonFactories&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;The Bean&amp;rsquo;s factory lambda&lt;/td&gt;
					&lt;td&gt;Right after instantiation&lt;/td&gt;
					&lt;td&gt;When the factory is called (promoted to level-2) or when the Bean completes&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Level-2 &lt;code&gt;earlySingletonObjects&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;The early-exposed half-built Bean&lt;/td&gt;
					&lt;td&gt;The moment the level-3 factory is called&lt;/td&gt;
					&lt;td&gt;When the Bean is fully initialized and placed in level-1&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Level-1 &lt;code&gt;singletonObjects&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;The complete, usable Bean&lt;/td&gt;
					&lt;td&gt;After initialization fully completes&lt;/td&gt;
					&lt;td&gt;When the container closes and destroys&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&#34;the-difference-between-beanfactory-and-factorybean&#34;&gt;The difference between BeanFactory and FactoryBean&lt;/h2&gt;
&lt;h3 id=&#34;what-is-a-factorybean&#34;&gt;What is a FactoryBean&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;interface&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;FactoryBean&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;T&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;// Return the Bean instance (can involve complex creation logic)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    T &lt;span style=&#34;color:#a6e22e&#34;&gt;getObject&lt;/span&gt;() &lt;span style=&#34;color:#66d9ef&#34;&gt;throws&lt;/span&gt; Exception;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;// Return the Bean&amp;#39;s type&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    Class&lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;?&amp;gt;&lt;/span&gt; getObjectType();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;// Whether it&amp;#39;s a singleton&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;default&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;boolean&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;isSingleton&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;true&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;Similarities
&lt;ul&gt;
&lt;li&gt;Both are used to create Bean objects&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Differences
&lt;ul&gt;
&lt;li&gt;Creating an object with BeanFactory must follow the strict lifecycle process, which is too complex. If you want to simply customize the creation of some object while still handing it to Spring to manage, you must implement the FactoryBean interface
&lt;ul&gt;
&lt;li&gt;isSingleton — whether it&amp;rsquo;s a singleton&lt;/li&gt;
&lt;li&gt;getObjectType — get the returned object&amp;rsquo;s type&lt;/li&gt;
&lt;li&gt;getObject — customize the object-creation process&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Dimension&lt;/th&gt;
					&lt;th&gt;BeanFactory&lt;/th&gt;
					&lt;th&gt;FactoryBean&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;strong&gt;Role&lt;/strong&gt;&lt;/td&gt;
					&lt;td&gt;Container/factory interface&lt;/td&gt;
					&lt;td&gt;A special Bean&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;strong&gt;Function&lt;/strong&gt;&lt;/td&gt;
					&lt;td&gt;Manages the lifecycle of all Beans&lt;/td&gt;
					&lt;td&gt;Customizes the creation of a specific Bean&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;strong&gt;Positioning&lt;/strong&gt;&lt;/td&gt;
					&lt;td&gt;Infrastructure (the IOC container)&lt;/td&gt;
					&lt;td&gt;Business extension (creating complex objects)&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;strong&gt;How it&amp;rsquo;s used&lt;/strong&gt;&lt;/td&gt;
					&lt;td&gt;Implemented and used by the Spring framework&lt;/td&gt;
					&lt;td&gt;Implemented by the developer, registered into the container&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;strong&gt;Common implementations&lt;/strong&gt;&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;DefaultListableBeanFactory&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;SqlSessionFactoryBean&lt;/code&gt;, &lt;code&gt;ProxyFactoryBean&lt;/code&gt;&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;strong&gt;Who creates whom&lt;/strong&gt;&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;BeanFactory&lt;/code&gt; creates and manages &lt;code&gt;FactoryBean&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;&lt;code&gt;FactoryBean&lt;/code&gt; creates business objects&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;hr&gt;
&lt;pre class=&#34;mermaid&#34;&gt;flowchart LR
    subgraph BeanFactory[BeanFactory - IOC container]
        direction LR
        Bean1[ordinary Bean]
        Bean2[ordinary Bean]
        FB[FactoryBean&lt;br/&gt;special Bean]
    end

    FB --&gt;|call getObject| Result[business object]
    
    User[developer] --&gt;|getBean| BF[BeanFactory]
    BF --&gt;|return| Bean1
    BF --&gt;|return| Bean2
    BF --&gt;|return getObject result| Result
    BF --&gt;|add &amp; prefix| FB
&lt;/pre&gt;
&lt;h2 id=&#34;design-patterns-used-in-spring&#34;&gt;Design patterns used in Spring&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Singleton&lt;/li&gt;
&lt;li&gt;Prototype (scope set to prototype)&lt;/li&gt;
&lt;li&gt;Factory
&lt;ul&gt;
&lt;li&gt;BeanFactory&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Template Method
&lt;ul&gt;
&lt;li&gt;JdbcTemplate&lt;/li&gt;
&lt;li&gt;TransactionTemplate&lt;/li&gt;
&lt;li&gt;RestTemplate&lt;/li&gt;
&lt;li&gt;RedisTemplate&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Strategy
&lt;ul&gt;
&lt;li&gt;XmlBeanDefinitionReader&lt;/li&gt;
&lt;li&gt;PropertiesBeanDefinitionReader&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Observer
&lt;ul&gt;
&lt;li&gt;listener&lt;/li&gt;
&lt;li&gt;event&lt;/li&gt;
&lt;li&gt;multicast&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Adapter
&lt;ul&gt;
&lt;li&gt;HandlerAdapter&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Decorator
&lt;ul&gt;
&lt;li&gt;BeanWrapper&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Chain of Responsibility
&lt;ul&gt;
&lt;li&gt;When using AOP, an interceptor chain is generated first&lt;/li&gt;
&lt;li&gt;The filter chain of Spring MVC&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Proxy
&lt;ul&gt;
&lt;li&gt;Dynamic proxy&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Delegate
&lt;ul&gt;
&lt;li&gt;delegate&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;the-underlying-implementation-principle-of-spring-aop&#34;&gt;The underlying implementation principle of Spring AOP&lt;/h2&gt;
&lt;h3 id=&#34;-level-1-characterize-it-in-one-sentence-opening&#34;&gt;🥇 Level 1: characterize it in one sentence (opening)&lt;/h3&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;ldquo;The underlying essence of Spring AOP is &lt;strong&gt;dynamic proxy&lt;/strong&gt;. When the container initializes a Bean, Spring intercepts via the &lt;code&gt;BeanPostProcessor&lt;/code&gt; mechanism, decides whether the Bean needs enhancement, and if so, uses a dynamic proxy to generate a proxy object that replaces the original Bean when registered into the container. All subsequent calls to this Bean actually go through the proxy object.&amp;rdquo;&lt;/p&gt;</description>
    </item>
    <item>
      <title>MySQL: Interview Questions</title>
      <link>https://lv-blog.pages.dev/en/posts/programming/for-interview/mysql-interview-questions/</link>
      <pubDate>Thu, 19 Sep 2024 23:19:24 +0800</pubDate>
      <guid>https://lv-blog.pages.dev/en/posts/programming/for-interview/mysql-interview-questions/</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;These interview questions were collected from every corner of the internet&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&#34;how-do-you-locate-a-slow-query&#34;&gt;How do you locate a slow query?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Approach 1
&lt;ul&gt;
&lt;li&gt;Open-source tools
&lt;ul&gt;
&lt;li&gt;Arthas&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Ops tools
&lt;ul&gt;
&lt;li&gt;Prometheus&lt;/li&gt;
&lt;li&gt;Skywalking&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Approach 2
&lt;ul&gt;
&lt;li&gt;MySQL&amp;rsquo;s built-in slow log (has a performance cost)
&lt;ul&gt;
&lt;li&gt;How to enable the slow log
&lt;ul&gt;
&lt;li&gt;/etc/my.conf
&lt;ul&gt;
&lt;li&gt;slow_query_log&lt;/li&gt;
&lt;li&gt;long_query_time&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;a-sql-statement-runs-slowly--how-do-you-analyze-it&#34;&gt;A SQL statement runs slowly — how do you analyze it?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Reasons for slowness
&lt;ul&gt;
&lt;li&gt;Aggregate queries&lt;/li&gt;
&lt;li&gt;Multi-table queries&lt;/li&gt;
&lt;li&gt;Queries on tables with too much data&lt;/li&gt;
&lt;li&gt;Deep pagination queries&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;How to analyze the slowness
&lt;ul&gt;
&lt;li&gt;The explain / desc command
&lt;ul&gt;
&lt;li&gt;How to read the result?
&lt;ul&gt;
&lt;li&gt;The extra optimization hints
&lt;ul&gt;
&lt;li&gt;using where; using index — the lookup used an index, and the needed data is all in the index columns, so no back-to-table lookup is needed&lt;/li&gt;
&lt;li&gt;using index condition — the lookup used an index&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;type
&lt;ul&gt;
&lt;li&gt;index, all — need optimization&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;do-you-know-about-indexes-what-is-an-index&#34;&gt;Do you know about indexes? What is an index?&lt;/h2&gt;
&lt;p&gt;An index is a data structure (ordered) that helps MySQL fetch data efficiently. Beyond the data itself, the database system maintains data structures that satisfy specific search algorithms (such as B+ trees); these structures reference (point to) the data in some way, so advanced search algorithms can be implemented on them. Such a data structure is an index.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
