Adobe Interview Question for Member Technical Staffs


Country: India




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

May be using decorator pattern , extend the same class and add synchronization to the extended class.

- Vijay May 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The safest way is to ensure that only one thread calls into the third-party library at a time - that is, take a mutex around EVERY call to the library. Making it so that multiple threads can use the library at once. This could be implemented using Semaphore.

class Pool {
//you have only one instance.
private static final MAX_AVAILABLE = 1;

private final Semaphore available = new Semaphore(MAX_AVAILABLE, true);

public Object getItem() throws InterruptedException {
available.acquire();
return getNextAvailableItem();
}

public void putItem(Object x) {
if (markAsUnused(x))
available.release();
}

// Not a particularly efficient data structure; just for demo

protected Object[] items = <your third pary library item here.>
protected boolean[] used = new boolean[MAX_AVAILABLE];

protected synchronized Object getNextAvailableItem() {
for (int i = 0; i < MAX_AVAILABLE; ++i) {
if (!used[i]) {
used[i] = true;
return items[i];
}
}
return null; // not reached
}

protected synchronized boolean markAsUnused(Object item) {
for (int i = 0; i < MAX_AVAILABLE; ++i) {
if (item == items[i]) {
if (used[i]) {
used[i] = false;
return true;
} else
return false;
}
}
return false;
}

}

http://docs.oracle.com/javase/1.5.0/docs/api/index.html?java/util/concurrent/Semaphore.html

- cCAACc May 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Need to have more context. When you third party being used, are the thread going to share the same instances, or they will work independently on that library?

- Hello world May 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

make all library functions reentrant

- Anonymous May 06, 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