1
我在for循環中創建了一些可調用線程,並在我的main方法中啓動了所有這些線程。如果我在主要方法中執行Thread.sleep(10000),子線程會發生什麼
啓動所有線程後,我有Thread.sleep(10000)
。在這種情況下,我的子可調用線程會發生什麼情況。
psudocode:
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);
}
}
}
在上面的代碼第i個已創建15個線程。在第二個循環(outer while)中,如果values size大於5,我在做Thread.sleep(),在這個時候,創建的子線程會發生什麼?子線程是否也會進入睡眠模式或子線程會發生什麼。
請幫忙。你的幫助將非常可觀。 謝謝。