singleton object
单例对象
2026-03-22 09:40 浏览次数 33
单例对象
thread 1 executes and because instance is still null at //2, creates a singleton object and assigns its reference to instance.
线程1执行,由于在 //2 处实例仍旧为null,线程 1还创建一个singleton对象并将其引用赋值给instance。
thread 1 starts where it left off and executes line //2 which results in another singleton object being created.
线程1在它停止的地方启动,并执行 //2 代码行,这导致创建另一个singleton对象。
how to run test cases for singleton object with multiple state?
如何运行多个状态对象的测试用例?
copies of a singleton object that has undergone serialization and deserialization.
通过序列化和反序列化去复制一个单例对象。
now, we can call the reset method to start off each test run to ensure we are going through the initialization code for the singleton object on every test run.
现在,我们可以在每次测试之前调用reset方法,保证我们在每次测试过程中都会先执行singleton对象的初始化代码。
instead, scala supports a singleton object construct to support those cases where exactly one instance of a type is needed.
相反,scala支持单例模式,可以应用于那些一种类型只有一个实例的情况。
this line of code creates a singleton object and initializes the variable instance to refer to this object.
此行代码创建了一个singleton对象并初始化变量instance来引用此对象。
because instance is non-null, a second singleton object is not created and the one created by thread 1 is returned.
由于instance是非null 的,并没有创建第二个singleton对象,由线程1创建的对象被返回。
thread 2 returns the singleton object reference at //3.
线程2在 //3 处返回singleton对象引用。
the code at be allocates the memory from the heap for the singleton object and stores a pointer to that memory in eax.
be处的代码为singleton对象从堆中分配内存,并将一个指向该块内存的指针存储到eax 中。
all calls to a singleton object are handled by one instance of that object.
所有对单一物件的呼叫都是由该物件的一个执行个体所处理。
a scitter singleton object handles those operations that don't require an authenticated user.
一个scitter 独立对象,处理那些不需要对用户进行验证的操作。
to wit, compiler optimizations can make the assignment of the new singleton object before all its fields are initialized. (see 「double-checked locking is broken」 in resources.)
为了更加智能化,编译器优化会在单例对象所有域完全初始化前就创建该单例对象(参见《重复检查锁的致命点》)。
all operations are generally backed by a singleton object instance.
所有操作通常都是由一个单独的对象实例提供支持。
in that case, a new singleton object will be created.
在这种情况下,一个新的单例对象会被创建。
the code in listing 10 does not use synchronization and ensures that the singleton object is not created until a call is made to the static getinstance() method.
清单10的代码没有使用同步,并且确保调用staticgetinstance()方法时才创建singleton。
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.
此类提供了一组类或一组单例(singleton)对象实例,在一个jax-rs应用程序内包括所有的根级别的资源和提供程序(由 @provider注释的类)。
thread 1 then assigns a fully constructed singleton object to the variable instance at //5 and exits both synchronized blocks.
线程1然后将一个构造完整的singleton对象在 //5 处赋值给变量instance,并退出这两个synchronized块。
thread 1 completes the initialization of the singleton object by running its constructor and returns a reference to it.
线程1通过运行singleton对象的构造函数并将引用返回给它,来完成对该对象的初始化。
thread 2 enters the if block and creates a new singleton object and assigns the variable instance to this new object at //2.
线程2进入if代码块并创建一个新的singleton对象并在 //2 处将变量instance分配给这个新对象。