Question

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.

Was it helpful?

Solution

Several ideas abbout what might be wrong:

  • You might open only one connection (Sybase Client was not Multithread-save, when I worked with it some years ago)
  • The Stored Procedure locks some table that lets the second call wait and block. Do the SP's some kind of insert, update, delete on a table somewhere at the beginning? Maybe inside of a transaction? Well, then the second SP will wait for the first one to finish.
  • I remember on Sybase one issue for a long time was, to create some object (table, columns, view, temporary table etc.) which exclusively locked some system tables and let the second SP wait for the first one to finish the creation. Maybe somebody can advice, if that still can happen.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top