Tag:Single case

  • Easy to understand design pattern (Part 1)

    Time:2022-6-22

    1、 Singleton mode 1. what is singleton mode The definition of the singleton pattern is to ensure that a class has only one instance and provide a global access point to access it. There are some objects, such as in the thread pool / global cache / browserwindowObjects, etc., we only need one instance. The […]

  • About singleton and prototype in spring

    Time:2022-6-20

    We often use singleton beans that depend on singleton beans. What should we do when singleton beans depend on prototype beans? There are two ways:1、 Declare the dependent bean as prototype, and then use applicationcontext GetBean (xxx). We know that the non lazy loading singleton bean will be created only once when spring starts, and […]

  • Talk about singleton mode and several implementations again

    Time:2022-6-16

    catalogue 1、 What about singleton mode 2、 Classic single thread single instance 3、 Classic double locking multithreading singleton (jdk5-jdk7 continue to apply) 4、 Multithreaded singleton after jdk8 4.1 synchronized to lightweight lock 4.2 using the initialization feature of static inner classes 5、 Is there any way to make the singleton mode not singleton? 6、 Enumeration […]

  • Objective-C singleton macro

    Time:2022-6-9

    realization Post code firstYou can also visit my github:RWSingleton #import <objc/runtime.h> #define RW_DECLARE_SINGLETON_FOR_CLASS_WITH_ACCESSOR(classname, accessorMethodName) \ + (classname *)accessorMethodName; #if __has_feature(objc_arc) #define RW_SYNTHESIZE_SINGLETON_RETAIN_METHODS #else #define RW_SYNTHESIZE_SINGLETON_RETAIN_METHODS \ – (id)retain \ { \ return self; \ } \ \ – (NSUInteger)retainCount \ { \ return NSUIntegerMax; \ } \ \ – (oneway void)release \ { \ } […]

  • 「Golang」sync. Once usage and source code explanation

    Time:2022-6-3

    preface In our development process, we often use the classic design pattern of singleton mode. Singleton mode can help developers perform initialization or function call operations only once during program operation for a certain variable or object or function (method), such as initialization for a certain type of connection pool (such as database connection pool) […]

  • Deep understanding of sync Once: a great choice for singleton mode

    Time:2022-5-31

    Sync Once is an implementation that allows function methods to be called and executed only once. It is most often used in singleton mode, such as initializing system configuration, maintaining unique database connections, and so on. Sync Example of singleton mode for once `1package main` `2` `3import (` `4    “fmt”` `5    “sync”` `6)` `7` `8type Instance struct{}` `9` `10var (` `11    once     sync.Once` `12    instance *Instance` […]

  • Chapter 3 of the spring hand column: first show your skills and use design patterns to realize the definition, registration and acquisition of beans

    Time:2022-5-30

    Author: Xiao FugeBlog:https://bugstack.cn Precipitation, sharing, growth, so that they and others can gain! 1、 Foreword Can you foresee the design problems of complex content? It is reasonable to say that no matter whether the product functions are complex or not, a large number of programmers will write a pile of if Else to complete the […]

  • How to do spring source code analysis?

    Time:2022-5-30

    target Track the flow of the following code: AnnotationConfigApplicationContextDemo /** * description * date 2021-06-30 11:21 **/public class AnnotationConfigApplicationContextDemo { public static void main(String[] args) { final AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(SimpleConfig.class); User user = applicationContext.getBean(User.class); System.out.println(“user:” + user); } }Configurationpublic class SimpleConfig { Bean public User user(){ return new User(“xgimi”, 10); } }public class User { private String name; private Integer age;         … flow […]

  • Spirng execution process

    Time:2022-5-29

    I haven’t blogged for a long time. Today, the missing people return This is an original spring IOC container startup method. We need the annotationconfigapplicationcontext class to have the following steps 1. create a constructor and get the scan path according to @componentscan (value = “com.zhongyu”) on the AppConfig configuration class we passed in 2. […]

  • In depth source code analysis of golang sync Once

    Time:2022-5-29

    What is sync Once The official document describes it as follows: an object will be fully executed once and cannot be copied. It is often used for initialization scenarios of singleton objects, or for concurrent access to shared resources that only need to be initialized once. Sync Once only exposes one method do, which can […]

  • Analysis of golang package sync (I): sync Once

    Time:2022-5-26

    preface Go language provides a lot of support for synchronization (data synchronization and thread synchronization) in design, such as goroutine and channel synchronization primitives, which are available at the library level Sync: provides basic synchronization primitives (such as mutex, rwmutex, locker) and tool classes (once, waitgroup, cond, pool, map) Sync / atomic: provides atomic operations […]

  • IOS development – single case

    Time:2022-5-25

    What is a single case, the purpose of a single case? When a class has only one instance, you need to use a singleton, that is, the class has only one object. This object cannot be released during program operation, and can be used to record data and transfer values Single case writing format Common […]