- Q The first session of the constituent Assembly was held in?
- Q What are different models in CMMI?
- Q What is the msi mode in weblogic? how can you enable and disable this option
- Q He was an American psychologist who was best known for creating ”Hierarchy of needs" during 1943, represented as a pyramid with the more basic needs at the bottom. (A)Alfred Adler (B)Avram Noam Chomsky (C)Abraham Maslow (D)Patrick Geddes
- Q Name the head quarters and president of International Bank for Reconstruction and Development (IBRD).
- Q What is the difference between Ant and Maven?
- Q India’s first of its kind conclave, national Women’s parliament (NWP) was organized in?
- Q What are the master data pre-requisites for document clearing?
- Q What is the Chilean Pine more commonly known as?
- Q What were the deciding factors that made you choose that particular solution?
- Q We called the doctor because Prasad was complaining ____ a pain in his abdomen.
Question
What is double checked locking in Singleton
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
Answers
Double checked locking is a technique to prevent creating another instance of Singleton when call to getInstance() method is made in multi-threading environment. In Double checked locking pattern as shown in below example, singleton instance is checked two times before initialization.
public static Singleton getInstance()
{
if(_INSTANCE == null)
{
synchronized(Singleton.class)
{
//double checked locking - because second check of Singleton instance with lock
if(_INSTANCE == null)
{
_INSTANCE = new Singleton();
}
}
}
return _INSTANCE;
}
Double checked locking should only be used when you have requirement for lazy initialization otherwise use Enum to implement singleton or simple static final variable. Your Comment
public static Singleton getInstance()
{
if(_INSTANCE == null)
{
synchronized(Singleton.class)
{
//double checked locking - because second check of Singleton instance with lock
if(_INSTANCE == null)
{
_INSTANCE = new Singleton();
}
}
}
return _INSTANCE;
}
Double checked locking should only be used when you have requirement for lazy initialization otherwise use Enum to implement singleton or simple static final variable. Your Comment
- 0
- 0
- New Answer
- Contributors: *,
More Software Questions..
What is the inputsplit in map reduce software?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What is software configuration management?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What Is Java Api For Xml-based Rpc (jax-rpc)?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
How can you implement fine-grained auditing?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What is IBM’s simple explanation for Big Data’s four critical features?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What is static synchronized method in JDBC API? Give an example?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What does the NULLIF function do?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What happens if a start method is not invoked and the run method is directly invoked?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
Should we override finalize method
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
what is the difference between mysql_fetch_array and mysql_fetch_object?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
How will XML affect my document links?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
Why to use Style Sheets?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What are Filters in MVC?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
Can you explain Application layer in OSI model?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
How to define new testplan attributes?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What are the minimum system requirements to run Photoshop? Is it possible to run Photoshop over linux?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
Which oracle package is used to manage the oracle lock management services?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What is Latch Up? Explain Latch Up with cross section of a CMOS Inverter. How do you avoid Latch Up?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What is marker interface?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What types of partitioning are there for BW?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,