নথিপত্র

একক প্যাটার্ন শুধু এক উদাহরণস্বরূপ মাল্টি থ্রেডিং তৈরি করা হয়

while using the singleton pattern, only one instance is created in multi threading?

Using threadsafe singleton class will guarantee that only one instance is created.

public sealed class Singleton
{
private static Singleton singleton = null;
private static readonly object singletonLock = new object();

private Singleton() {}
public static Singleton GetInstance()
{
lock (singletonLock)
{
যদি (singleton == null)
{
singleton = new Singleton();
}
return singleton ;
}
}
}

Issue will raise only when the creation of first instance.

Using lock() will provide us the thread safe to avoid execution of two threads at a same time to create instance.

Again we are verifying the (singletonobject == null) so it will guarantee that only once instance will be created.

double check option will be full proof for our class.

একটি উত্তর ত্যাগ

আপনি ব্যবহার করতে পারেন এই HTML ট্যাগ

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>