Flipkart Interview Question for Software Engineer / Developers






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

One code example

import java.util.*;

public class test2 implements Runnable{
	String s1 ;
	String s2 ;
	
	public test2(String s1, String s2){
		this.s1 = s1;
		this.s2 = s2;
	}
	
	public void printOne() throws Exception{
		synchronized(s1){
			Thread.sleep(10000);
			synchronized(s2){
				System.out.println (s1 + s2);
			}
		}
	}
	
	public void printTwo() throws Exception{
		synchronized(s2){
			Thread.sleep(10000);
			synchronized(s1){
				System.out.println (s1 + s2);
			}
		}
	}
	
	public void run() {
		try{
			printOne();
		}catch(Exception e){
			
		}
	}
	
	public static void main(String[] args) throws Exception{
		String s1 = "dead";
		String s2 = "lock";
		test2 t = new test2(s1, s2);
		new Thread(t).start();
		t.printTwo();
	}
}

- boyjemmy July 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package com.interview.flipkart;



public class DeadLockExample extends Runnable{
static int a = 0;
static int b = 0;

boolean aOrb = false;

public static synchronized void setA(int ia){
this.a = a;
System.sleep(1000000L);
setB(ia/2);
}

public static synchronized void setB(int ib){
this.b= ib;
System.sleep(1000000L);
setA(2*ib);
}

public void run(){
if(aOrB){
setA(10);
}else{
setB(5);
}
}

public statis void main(String[] args){
DeadLockExample de1 = new DeadLockExample();
DeadLockExample de2 = new DeadLockExample();
del.aOrb = true;
de2.aOrb = false;
Thread th1 = new Thread(de1);
Thread th2 = new Thread(de2);
th1.start();
th1.start();
}
}

- Ashok Gupta April 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package com.interview.flipkart;



public class DeadLockExample extends Runnable{
	static int a = 0;
	static int b = 0;
	
	boolean aOrb = false;
	
	public static synchronized void setA(int ia){
		this.a = a;	
		System.sleep(1000000L);
		setB(ia/2);
	}
	
	public static synchronized void setB(int ib){
		this.b= ib;
		System.sleep(1000000L);
		setA(2*ib);	
	}
	
	public void run(){
		if(aOrB){
			setA(10);
		}else{
			setB(5);
		}	
	}
		
	public statis void main(String[] args){
		DeadLockExample de1 = new DeadLockExample();
		DeadLockExample de2 = new DeadLockExample();
		del.aOrb = true;
		de2.aOrb = false;
		Thread th1 = new Thread(de1);
		Thread th2 = new Thread(de2);
		th1.start();
		th1.start();	
	}
}

- ashok gupta April 16, 2011 | 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