Walmart Labs Interview Question for Applications Developers


Country: India
Interview Type: In-Person




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

You will have write the code by yourself using wait() and Notify() to implement the functionality same as join. yes we can do it.

- Soumitrav December 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

There is one more solution with CountDownLatch.

public class ThreadJoinTest {

	@Test
	public void testThreadJoin() {
		ThreadJoin t = new ThreadJoin(new Runnable() {
			@Override
			public void run() {
				try {
					TimeUnit.SECONDS.sleep(3);
				} catch(InterruptedException e) {
					System.err.println(e.getMessage());
				}
				System.out.println("Task has been finished");
			}
		});
		t.start();
		t.threadJoin();
		assertThat(t.getState(), is(equalTo(Thread.State.TERMINATED)));
	}
}

public class ThreadJoin extends Thread {
	
	private CountDownLatch latch = new CountDownLatch(1);

	public ThreadJoin(Runnable runnable) {
		super(runnable);
	}
	
	

	@Override
	public void run() {
		super.run();
		latch.countDown();
	}



	public void threadJoin() {
		try {
			latch.await();
		} catch (InterruptedException e) {
			System.err.println("Exception occured while joining");
			e.printStackTrace();
		}
	}

}

- Anton December 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use ExecuterService here. Create a Service with Pool as:
ExecutorService ex = Executors.newSingleThreadExecutor();

This will make threads work sequentially

- Himanshu April 02, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

Set the buffer size while creating the reader
Reader input = new BufferedReader(new FileReader("file.txt"), 8 * 1024);

- thulasi.nari December 13, 2014 | 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