java - running multiple threads simultaneously -
help me please. run threads array in 1 time
public class main { public static void main(string[] args) { string [] folders = (new counter()).readfile(); thread[] threads = new thread[folders.length]; (int = 0; < folders.length; i++) { threads[i] = new thread(new mythread(folders[i])); } startthreads(threads); } private static void startthreads(thread[] threads) { (thread t : threads) t.start(); } }
other executors,but in case have n threader, wait each other. http://joxi.ru/b6aqvp3jtjbmfbw41ma
string [] folders = (new counter()).readfile(); thread[] threads = new thread[folders.length]; int size= folders.length; (int = 0; < folders.length; i++) { threads[i] = new thread(new mythread(folders[i])); } executorservice executor = executors.newfixedthreadpool(folders.length); (int = 0; < size; i++) { runnable worker = new mythread(folders[i]); executor.execute(worker); } executor.shutdown(); while (!executor.isterminated()) { } system.out.println("finished threads");
Comments
Post a Comment