[英]Java Executor - not running threads in parallel
I am trying to execute independent task parallel using the java.util.concurrent.Executor
. 我正在尝试使用
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. 但问题是,当我更换
WorkerThread
与我的其他类,这是Runnable
,并通过连接到数据库做一个存储过程调用。 In that case, the threads are getting started but the actual call to stored procedures seems to be in a procedural way ie the 2nd java-proc call is not getting executed until the first one finishes. 在那种情况下,线程正在启动,但是对存储过程的实际调用似乎是以一种过程方式进行的,即直到第一个java-proc调用才开始执行。
The database part is working fine, as that is verified and tested independently. 数据库部分运行良好,因为它是独立验证和测试的。 I just need to kick 2-3 calls simultaneously.
我只需要同时踢2-3个电话即可。 I am using Sybase as the database.
我正在使用Sybase作为数据库。
Has anyone encountered this problem before? 有人遇到过这个问题吗? Please let me know what could be possibly wrong.
请让我知道可能出了什么问题。
Several ideas abbout what might be wrong: 关于可能存在问题的一些想法:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.