/* This is my Main thread */
CountDownLatch startSignal = new CountDownLatch(1);
CountDownLatch doneSignal = new CountDownLatch(3);
ToolThread[] runThread = new ToolThread[3]
for (int i = 0; i < 3; i++) {
runThread[i] = new ToolThread(i);
runThread[i].start();
startSignal.countDown(); // let all threads proceed
int return = runThread[i].getStatus();
if (return != 0) {//this means error
// forcing the latch count to zero
for (; doneSignal.getCount() > 0; doneSignal.countDown()){}
}
doneSignal.await(); // wait for all to finish
}
class ToolThread extends Thread {
private final CountDownLatch startSignal;
private final CountDownLatch doneSignal;
private int status;
ToolThread(CountDownLatch startSignal, CountDownLatch doneSignal) {
this.startSignal = startSignal;
this.doneSignal = doneSignal;
}
public int getStatus(){
return status;
}
public void run() {
try {
startSignal.await();
status = doWork();
doneSignal.countDown();
}
catch (InterruptedException ex) {}
}
}
/* This is my Main thread */
ToolThread[] runThread = new ToolThread[3]
for (int i = 0; i < 3; i++) {
runThread[i] = new ToolThread(i);
runThread[i].start();
}
for (int j = 0;j<3;j++) {
try {
runThread[i].join();
}
catch (InterruptedException ex) {
}
}
class objectArray {
public static void main(String[] args) {
String[] args = {"abc", "123"}
CreateObjArr[args.length] obj;
for (int i=0;i<args.length;i++) {
String str = args[i];
//creating each object differently
obj[i] = new CreateObjArr(args);
obj[i].getString();
}
}
}
long currentTime = Calendar.getInstance().getTimeInMillis();
long requiredTime = currentTime + 600000;
while(Calendar.getInstance().getTimeInMillis() < requiredTime)
try{
func1();
}
catch(SQLException e){
if (ex.getErrorCode() == 00060){
while (///a condition that will run this for 10 minutes){
try{
func1();
break; // if here means execution was successful hence break.
}catch(SQLException e){
// handling here
Thread.sleep(500);
}
}
}
}
try{
func1();
}
catch(SQLException e){
if (ex.getErrorCode() == 00060){
while (///a condition that will run this for 10 minutes){
try{
func1();
break; // if here means execution was successful hence break.
}catch(SQLException e){
// handling here
}
}
}
}