A9 Interview Question for Software Engineer in Tests


Country: United States




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

Simple answer is it will never be thread safe if it is only static. Because static variables make sure that only one copy will be shared by all objects of that class, thats why static variable belongs to class. But it never says that static variables and methods will be thread safe. To make it thread safe, you have to use synchronize keyword over the Class object for that class.

- Ghosh September 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

There exists only one copy of each method per class, be the method static or non-static. A thread needs to acquire the monitor of an appropriate object before entering a synchronized method which it releases when the thread returns from the method. In case of static synchronization the thread acquires the monitor of the class object, the locking is at class level so no other thread can execute it until the current thread releases the lock. In case of non-static synchronisation the thread acquires the monitor of that particular instance on which the call was made so other threads using different instances are not locked. They acquire monitors of there respective instances but continue to execute, as no two thread use the same instance.

- fReaK September 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static objects use the heap area , which is common access to all threads. We need to apply synchronization techniques (semaphore,mutex,lock etc) to deal with it.

synchronized keyword in java is also very handy to use.

- saumya.wipro April 09, 2015 | 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