I am trying to execute independent task parallel using the java.util.concurrent.Executor
.
I have the following working code
public class MiniTest {
private static String[] input;
static {
input = new String[] {
"task1",
"task2",
"task3",
"task4"
};
}
public static void main(String[] args) throws InterruptedException {
ExecutorService executor = Executors.newFixedThreadPool(2);
boolean atleastOnePoolStarted = false;
for (int i = 0; i < input.length; i++) {
Runnable worker = new WorkerThread(input[i] + i);
executor.execute(worker);
}
executor.shutdown();
executor.awaitTermination(15,TimeUnit.MINUTES);
System.out.println("Finished all threads");
}
}
This is working fine, and I see parallel execution.
But the problem is, when I am replacing the WorkerThread
with my other class which is Runnable
and does a stored procedure call by connecting to database. In that case, the threads are getting started but the actual call to stored procedures seems to be in a procedural way i.e. the 2nd java-proc call is not getting executed until the first one finishes.
The database part is working fine, as that is verified and tested independently. I just need to kick 2-3 calls simultaneously. I am using Sybase as the database.
Has anyone encountered this problem before? Please let me know what could be possibly wrong.
Several ideas abbout what might be wrong: