多个单例对象存在于两个或多个虚拟机中。
多个单例对象被不同的类加载器同时加载。
Multiple singletons simultaneously loaded by different class loaders.
我们正在做的一件事是支持集群的单例服务。
One of the things we are working on is support for clustered singleton services.
那么,要怎么样来使用单例提供者呢?
单例创建模式是一个通用的编程习语。
The Singleton creation pattern is a common programming idiom.
您可以像调用静态方法一样访问单例对象的方法。
You can access methods on singleton objects similar to how you would call static methods.
清单4显示了使用方法而非属性来指定适当类的单例。
Listing 4 shows a version of the singleton that USES a method instead of an attribute to specify the appropriate class.
UI组件和应用对象(这是一个单例)都能收到系统事件。
Both UI components and the Application object (which is a singleton) can receive system events.
静态getInstance方法包含单例的模板代码。
The static getInstance method contains the template code for a singleton.
还记得吗,object表示 Scala中的一个单例。
我坚信,在大多数的框架中,使用单例模式时,考虑得都太少了。
It is my true belief that Singleton patterns have been used with far too little thought in most frameworks.
Singletonbean是一个在所属容器上下文中的单例对象。
A singleton bean is a singleton in the context of the owning container.
因此,除非仔细计划,否则应该避免使用JAX - RS资源的单例实例。
Therefore, use of a singleton instance for JAX-RS resources should be avoided unless carefully planned.
他们会发现每次他们要创建一个不同的单例类的时候,都不得不写同样得代码。
Those who use it will find that they often have to write the same code each time they want to create a different Singleton class.
当单例类的副本运行于多个虚拟机中时,每个虚拟机都会为其创建一个实例对象。
When copies of the singleton class run in multiple VMs, an instance is created for each machine.
Spring之前为bean提供了两种作用域:单例和原型(或者叫非单例)。
Spring has traditionally offered two scopes for beans: singleton and Prototype (or non-singleton).
相反,Scala支持单例模式,可以应用于那些一种类型只有一个实例的情况。
Instead, Scala supports a singleton object construct to support those cases where exactly one instance of a type is needed.
单例模式是一种有用的控制类访问的途径,他能保证只有一个类实例存在。
Singletons are a useful way to control access to a class, making sure that only one instance can exist.
更有甚者,单例对象能够被状态化;这样,它们可以作为一个状态仓库向外提供服务。
Moreover, singletons can be stateful; in this case, their role is to serve as a unique repository of state.
单例、生成器和工厂方法设计模式被视为是创建型的模式,因它们可协助对象的构建。
The singleton, builder, and factory method design patterns are considered creational patterns, as they assist in the construction of objects.
单例模式同样用于控制像数据库连接或者sockets这样的资源访问。
Singletons often control access to resources such as database connections or sockets.
所以如果两次序列化一个单例对象,这两个序列化得到的对象会持有两个不同的标识。
So if you serialize one singleton twice, the two serialized objects take on separate identities.
这是一个Scala单例(singleton),因为它使用对象声明,而不是类声明。
This is a Scala singleton because it USES the object declaration instead of a class declaration.
单例模式可能是最常用的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.
GameServer单例用于它的位置数组,其中保存了游戏面板上每个格子的当前状态。
The GameServer singleton is used for its positions array, which has the current state of each square on the game board.
这样分离出单例结构的代码,将有利于保持按单例模式使用类或不按单例模式使用类的灵活性。
This has the added benefit of separating singleton code from the class code leaving the flexibility to use several instances of the class or using the class as a singleton.
前面已经简单地介绍了单例模式的实现方式,现在让我们进入主题:两个单例对象如何同时存在?
Now that we've looked briefly at implementation, let's turn to the heart of this article: how two singletons can exist simultaneously.
清单10中的gameservice类是一个单例类,代表给定游戏的游戏服务器和当前状态。
The GameService class, in Listing 10, is a singleton class that represents the game server and the current state of the given game.
最后,在单例模式的一些实现方式中,单例类的子类能够动态地重载方法,这是静态方法所不能办到的。
With some implementations of the singleton, you allow writers of subclasses to override methods polymorphically, something not possible with static methods.
这篇文章中,讲解了几种会产生多个单例对象的情况,如果你发现了其他的情况,我非常乐意听到它们。
In this article, I've presented some ways that the multiple singleton might emerge. If you've discovered any others, I'd be interested in hearing about them.
应用推荐