Java concurrency - Is this efficient?
public class Client extends SelectCarOption {
public static void main(String args[]) {
Thread thread1 = new SelectCarOption();
thread1.run();
if (runType == 2) {
try {
thread1.sleep(5000); //stops thread1 to run different thread
} catch (InterruptedException e1) {
e1.printStackTrace();
}
Thread thread2 = new CarModelOptionsIO();
thread2.run();
try {
thread2.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
} else {
try {
thread1.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
So basically, I'm trying to run a program where the thread that is running
is determined by a variable runType. If runType is one value, a certain
thread will run and if it is the other, the other will run. Is my approach
the most efficient? Will it turn out to give any errors?
Friday, August 9, 2013
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment