Adobe Interview Question
Software Engineer / DevelopersI think this question may want to have a Singletron.
public class Singletron{
public static Singletron OnlyInstance;
private class Singletron(){}
public Singletron getInstance(){
if(OnlyInstance == null)
OnlyInstance = new Singletron();
return OnlyInstance;
}
/**** Other Class attributes and Methods ***/
}//end class
We want a only one instance of a process to be running at any given point. If we have the access to change the executable, we acquire a MUTEX with some name (say "onlyoneinstance") at the start of the process, and release this once we exit the process. If we are not able to acquire this MUTEX in the executable, we just exit.
This way only one instance of the executable will be running at any point of time.
I think it asks as to return only single object every time:
public class OnlyOneObject {
static OnlyOneObject obj;
static int count=0;
public static OnlyOneObject getIt(){
if(count==0)
{
obj=new OnlyOneObject();
count++;
return obj;
}
else
return obj;
}
public static void main(String[] args){
System.out.println(getIt().hashCode());
System.out.println(getIt().hashCode());
}
}
I believe that we want to run only one instance of a GIVEN exe. Say if is is abc.exe then if abc.exe is running, we can't run one more abc.exe in parallel, but we can run other exe like def.exe, dff.exe etc.
- Anurag Singh February 05, 2011If this is the question then, we can use following check before executing the exe.
<< UNIX Script>>
if[ $(ps -ef | grep abc.exe | grep -v grep | wc -l) -eq 0 ]; then
execute abc.exe
fi