[英]java rabbitmq with Executor thread, created threads keeps running. how to make sure threads are killed?
[英]Java Executor - not running threads in parallel
我正在尝试使用java.util.concurrent.Executor
并行执行独立任务。
我有以下工作代码
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");
}
}
一切正常,我看到了并行执行。
但问题是,当我更换WorkerThread
与我的其他类,这是Runnable
,并通过连接到数据库做一个存储过程调用。 在那种情况下,线程正在启动,但是对存储过程的实际调用似乎是以一种过程方式进行的,即直到第一个java-proc调用才开始执行。
数据库部分运行良好,因为它是独立验证和测试的。 我只需要同时踢2-3个电话即可。 我正在使用Sybase作为数据库。
有人遇到过这个问题吗? 请让我知道可能出了什么问题。
关于可能存在问题的一些想法:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.