is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
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.
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.
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.
Try running below code:
- Harry Dwiv May 27, 2015package test.careercup.threads;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class TestCondition {
public static void main(String[] args) {
PrintSequenceSingleMethod p = new PrintSequenceSingleMethod();
Thread1 thred1 = new Thread1(p, 1);
Thread1 thred2 = new Thread1(p, 2);
Thread1 thred3 = new Thread1(p, 3);
ExecutorService exec = Executors.newFixedThreadPool(3);
exec.execute(thred1);
exec.execute(thred2);
exec.execute(thred3);
exec.shutdown();
}
}
class Thread1 implements Runnable {
PrintSequenceSingleMethod obj;
int number;
Thread1(PrintSequenceSingleMethod obj, int n) {
this.obj = obj;
this.number = n;
}
@Override
public void run() {
for (;;)
obj.printNumber(number);
}
}
package test.careercup.threads;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
public class PrintSequenceSingleMethod {
public volatile int stateNumber = 1;
public final ReentrantLock lock = new ReentrantLock();
public final Condition condition1 = lock.newCondition();
public final Condition condition2 = lock.newCondition();
public void printNumber(int number) {
lock.lock();
try {
while (!(stateNumber == number))
condition1.await();
System.out.print(number);
stateNumber = number + 1;
condition1.signalAll();
if (stateNumber > 3) {
stateNumber = 1;
System.out.print("\n");
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
lock.unlock();
}
}
}