如果我在main方法中执行Thread.sleep(10000),子线程会发生什么

Abd*_*dul 1 java multithreading android java-ee

我在for循环中创建了一些可调用的线程,在我的main方法中启动了所有这些线程.

启动所有线程后我有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);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,我首先创建了15个Threads.在第二个循环(外部while)中,如果值大小大于5,我正在执行Thread.sleep(),此时创建的子线程会发生什么?Child线程是否也会进入睡眠模式或Child Threads会发生什么.

请帮助.你的帮助将非常值得一提.谢谢.

Thi*_*ilo 7

子线程不受父线程休眠(或终止,或几乎任何其他东西)的影响.他们会很开心.