Cisco Systems Interview Question


Country: India
Interview Type: In-Person




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

I think, Volatile can help. declare all the bean variable as volatile.

- a0125163 December 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This should be the answer for the question. We need to have a volatile variable common to both the threads if the value changes in first thread, the second thread will also know the changed value and hence the second thread will not see the stale data.

- arjunath123 December 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

You could also have a LastModified column. Any thread before doing a write, checks this column - if the date it has is earlier than the table date, then the thread again has to read the data and re-do the modifications.

- Vandana Gopal December 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I gave the answer, Interviewer was not satisfied and said it is a database specific solution, give me java specific solution.

- D December 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

one thing that can be done is update all the threads of the database update using asynchronous event notifications and handling...generally large applications uses something like a MVC design...even there might not be a UI, you can use similar kind of architecture where the database interaction is done through a seperate Singeleton thread altogether.

- The Artist December 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

If First thread is going to edit row data, First thread should take a read lock on the table row data, so that thread2 does not read a stale data which is going to be changed.

- kuldeep.hbti December 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Vandy : this is a good answer.

- Abhi January 29, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

what if thread 2 has already read the data?

- g June 29, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This shared data should be declared volatile, if Java is the language. If thread 2 has already read data before thread 1 making any change to it, thread 2 has read correct data at that time. After thread 1 has changed this data, this change will be visible to thread 1 too . A Volatile data means that all threads see the same data value and update by one thread to it should be visible to all the threads.

- kuldeep June 30, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

There is something called MESI protocol for multi-processor system. Similar kind of protocol can be used for multiple threads.

- Anonymous December 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

What about synchronized methods? "If an object is visible to more than one thread, all reads and writes to that object's variables are done through synchronized methods." : "h t t p://docs.oracle.com/javase/tutorial/essential/concurrency/syncmeth.html"

- Kamy December 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think you could not understand this question clearly.

- Anonymous December 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

how about to use jboss cache service.... it will read the data from cache before executing the update sql each time. and after update will update cache also

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

We can create queue for data base tasks. So all the threads will push their DB related task on db queue. The DB processing thread pops the tasks from queue and updates the data from DB and then process task.

This is called as scheduled-task pattern.

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

Use the version number concept like ORM does.

Have your update statement where clause to include the version that you read.

update *** set f1= value,versionnum=versionnum+1 where versionnum=<<versionnumber that you read>>

If other thread already commited, this update will be a no op.

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

Cisco gives hike once in 2-3 years.

New-Joinees only get hike after 2-3 years, so take 100% hike at the time of joining .. . otherwise don't cry after joining. :)

- Simple April 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can use two mutex one for a flag and other for writing data in database. Each thread before writing to data in database it will check flag.

- kumarabhi96 November 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

consider using optimistic locking.

- sumitkala308 September 08, 2016 | 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