Ebay Interview Question for Member Technical Staffs


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
2
of 2 vote

Serialize/Deserialize the Object to a Database.

Each JVM downloads the object from DB->locks the DB Row till the instance is used->Writes back the object to DB->Unlocks the row from Database.

- Abhi January 28, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

class Singleton
{
          private:
                Singleton();
                Singleton(const Singleton &copy);
                const Singleton& operator=(const Singleton &rhs);
          public:
                const Singleton& GetInstance()
                {
                      static Singleton _instance;
                      return _instance;
                 }
};

- Bijendra January 28, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Read
const Singleton& GetInstance() { }

as

static Singleton& GetInstance()
{
         static Singleton _instance;
         return _instance;
 }

- Bijendra January 28, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Use Enums
Item 3: Enforce the singleton property with a private constructor or an enum type

public enum Elvis {
	INSTANCE;
	public void leaveTheBuilding() { ... }
	}

- EffectiveJavaFollower March 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

Make it thread safe.

- hprem991 January 28, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Actually when i say cluster , different processes so threads dont share memory(including locks)

Imagine an application running in muliple Web App servers

- vasa.v03 January 28, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

//Lazy instantiation using double locking mechanism.
class Singleton
{
private static Singleton instance;

private Singleton()
{
System.out.println("Singleton(): Initializing Instance");
}

public static Singleton getInstance()
{
if (instance == null)
{
synchronized(Singleton.class)
{
if (instance == null)
{
System.out.println("getInstance(): First time getInstance was invoked!");
instance = new Singleton();
}
}
}

return instance;
}

public void doSomething()
{
System.out.println("doSomething(): Singleton does something!");
}
}

- Mohammad Husain January 28, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

in hadoop the counter is used like global accessibility. it's asynchronized during a task and get eventually synchronized after the task finished.

- zyfo2 January 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Guys there was this interesting article I read about making singleton class thread safe.

just before you create new instance, check if there is one already exist with do while loop.

- Anonymous January 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

options like JMS/DB or 3rd party tools like memcache . If WAS DistributedMap is built in and if Weblogic, Singleton Service. Terracotta and Oracle coherence are other ways. If Singleton is for cache, a simple timer with set refresh intervals works just as fine.

- Usha February 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This can be done through the readResolve method. When an object is read, replace it with the singleton instance. This ensures that nobody can create another instance by serializing and deserializing the singleton. For Example:

public final class MySingleton {
 private MySingleton() { }
 private static final MySingleton INSTANCE = new MySingleton();
 public static MySingleton getInstance() { return INSTANCE; }
 private Object readResolve() throws ObjectStreamException {
  // instead of the object we're on, 
  // return the class variable INSTANCE
  return INSTANCE; 
 }
}

This will ensure that only one instance is read when we are dealing with serialization/de-serialization.

- vinayknl.61 February 20, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More