它是一个单实例类。
原因在于多个虚拟机都可以涉及到相同的单实例类,这些单实例对象可能会同时存在于上下文中,从而导致这些单实例对象并不是全局唯一的。
The instance fields of the singleton will not be globally unique. Because several VMs are involved for what appears to be the same object, several singleton objects might be brought into existence.
由于单例对象作为实例存在而不是类的静态成员,所以你能够惰性地初始化单例对象,即只需要在第一次用它的时候才去创建它。
With singletons implemented as single instances instead of static class members, you can initialize the singleton lazily, creating it only when it is first used.
单例模式可能是最常用的OOP设计模式之一了;它限制了一个类的对象实例数只能为1。
The singleton pattern is probably one of the most often used OOP design patterns; it restricts the number of object instances of a class to one.
单例模式是一种非常有用的设计模式,它允许你的类对外只提供一个实例,但是常犯的错误在于不止一个实例被创建。
The singleton is a useful design pattern for allowing only one instance of your class, but common mistakes can inadvertently allow more than one instance to be created.
相反您可以定义一个对象(而不是类)并且它将成为类的一个单例实例。
Instead you can define some as an object (instead of a class) and it becomes a singleton instance of the class.
单例模式是一种有用的控制类访问的途径,他能保证只有一个类实例存在。
Singletons are a useful way to control access to a class, making sure that only one instance can exist.
由于子类的实例也是单例类的实例,所以可能出现多个单例实例并存的情况。
Since an instance of a subclass is an instance of your superclass, you could find multiple instances of the singleton.
比如数据库连接池就是单例设计模式的一个例子:我们一般不想让应用程序具有连接池类的多个资源密集型实例。
An example use case for a singleton would be a database connection pool: you don't want your application to have multiple resource-intensive instances of a connection pool class.
当单例类的副本运行于多个虚拟机中时,每个虚拟机都会为其创建一个实例对象。
When copies of the singleton class run in multiple VMs, an instance is created for each machine.
这是一个可用来创建单例类实例确不需要为每个特定的类重写单例模式代码的可重用的类。
This is a class that can be used repeatedly to instantiate a class as a singleton without having to re-write the singleton pattern code for that specific class.
我们将数据库当作一个单实例对象,以将database类限制为1个实例。
We made our database a singleton in order to limit the database class to only one instance.
此类提供了一组类或一组单例(singleton)对象实例,在一个JAX-RS应用程序内包括所有的根级别的资源和提供程序(由 @Provider注释的类)。
This class provides a set of classes, or a set of singleton object instances, that include all of the root-level resources and providers (classes annotated with @Provider) in a JAX-RS application.
创建一个SingletonFactory类去全局映射类名(或者是类对象)和单实例对象。
You can have a SingletonFactory class with a globally accessible map of class names or class objects to singleton instances.
单实例对象Message作为message类的元存储库和工厂类。
The Message singleton serves as a metadata repository and factory class for the Message class.
同时,如果使用创建单实例的方法实现单例模式,单例类还具有创建多个实例的变通能力。
Likewise, with a singleton implemented as single instance, you leave open the possibility of altering the class to create more instances in the future.
单例模式:确保一个类只有一个实例,并提供一个全局访问点。
The Singleton Pattern:ensures a class has only on instance, and provides a global point of access to it.
使用类来实现单例模式可以确保在任何时间只有一个实例对象。
Classes implementing Singleton pattern will ensure that only one instance of the object ever exists at any one time.
单例:保证一个类仅有一个实例,并提供一个访问它的全局访问点。
Singleton: one instance of a class or one value accessible globally in an application.
单例:保证一个类仅有一个实例,并提供一个访问它的全局访问点。
Singleton: one instance of a class or one value accessible globally in an application.
应用推荐