我在我的 main 方法中的 for 循环中创建了一些可调用线程,并启动了所有这些线程。
启动所有线程后,我有 Thread.sleep(10000)
。在这种情况下,我的子可调用线程会发生什么情况。
伪代码:
public static void main(String[] args){
Map<String, String> columnNames_TypesMap = tableUtil.getColumnNamesAndTypesFromOracleDB(toTable);
ExecutorService executor = Executors.newFixedThreadPool(50);
Set<Future<String>> values = Collections.newSetFromMap(new ConcurrentHashMap<Future<String>, Boolean>());
Future<String> value = null;
boolean valueSizeLogged = false;
long preValuesSize = values.size();
outer: while (true) {
//In the below method I am reducing values size.
count = tableUtil.checkIfAllRowsCopied(values, count, totalNoOfRecordsInFromTable);
if (values.size() > 5) {
logger.info("****** Hence we do not create new threads. We do wait for the created threads to compelte");
Thread.sleep(sleepTime);//Here I am putting my main thread to sleep
continue outer;
}
for (int indexForThread = 1; indexForThread <= 15; indexForThread++) {
startingRange = endingRanges + 1;
endingRanges = endingRanges + maxNoOfRecordsPerThread;
Callable<String> callable2 = new InsertionCallable(as400SchemaName + "." + fromTable, startingRange, endingRanges, columnNames_TypesMap, toTable);
value = executor.submit(callable2);//Child Thread
values.add(value);
}
}
}
在上面的代码中,我首先创建了 15 个线程。在第二个循环(外部 while)中,如果值大小大于 5,我正在执行 Thread.sleep(),此时创建的子线程会发生什么情况?子线程是否也会进入休眠模式或子线程会发生什么情况。
请帮忙。非常感谢您的帮助。 谢谢。
最佳答案
子线程不受父线程 hibernate (或终止,或其他任何事情)的影响。他们会很高兴地一起吃。
关于java - 如果我在 main 方法中执行 Thread.sleep(10000) ,子线程会发生什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45279348/