sirisha.malarapu
BAN USER
RepAnnOrr, abc at 8x8
As an Information and Record Clerk, I thrive on organization and precision, ensuring data is managed efficiently. With a keen ...
Repnnelsonvance, Animator at Cognzant Technology Solutions
I am the learning and development manager and play a key role in coordinating all corporate learning and development activities ...
RepFranHarris, abc at ADP
I am Fran, a dedicated and experienced manager with a strong background in Monlinks. With five years of professional experience ...
RepSuziCorni, Accountant at A9
I have strong critical and analytical skills with reading, writing, and comprehension. I have exceptional speaking skills without losing train ...
Replimlocica, News reporter at Smitty's Marketplace
Hello, I am a News reporter. Master's Degree in astrology and News reporter and 10 years of experience working ...
RepArnoldTate, Title searcher at Keeney's
I am a Title searcher with 8+ years of experience . In real estate business and law, a title search or ...
Repfriedcopeland, AOL tech support at 247quickbookshelp
My name is Frieda . I am a loan officer for a small real estate lender in Wahpeton, Texas. I specialize ...
import java.util.concurrent.locks.Condition;
- sirisha.malarapu February 15, 2018import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class PrintEvenOdd {
Lock lock;
Condition evenCondition;
Condition oddCondition;
public static void main(String[] args) {
PrintEvenOdd printEvenOdd = new PrintEvenOdd();
printEvenOdd.lock = new ReentrantLock();
printEvenOdd.evenCondition = printEvenOdd.lock.newCondition();
printEvenOdd.oddCondition = printEvenOdd.lock.newCondition();
Thread evenThread = new Thread(() -> {
printEvenOdd.printEven();
});
Thread oddThread = new Thread(() -> {
printEvenOdd.printOdd();
});
evenThread.start();
oddThread.start();
}
private void printEven() {
try {
lock.lockInterruptibly();
} catch (InterruptedException e) {
}
int i = 0;
while (i < Integer.MAX_VALUE) {
if (i % 2 == 0) {
System.out.print(i + " ");
if(i % 10 == 0)
System.out.println();
oddCondition.signal();
try {
evenCondition.await();
} catch (InterruptedException e) {
}
}
i += 1;
}
lock.unlock();
}
private void printOdd() {
try {
lock.lockInterruptibly();
} catch (InterruptedException e) {
}
int i = 0;
while (i < Integer.MAX_VALUE) {
if (i % 2 == 1) {
System.out.print(i + " ");
evenCondition.signal();
try {
oddCondition.await();
} catch (InterruptedException e) {
}
}
i += 1;
}
lock.unlock();
}
}