If you have a list of class names in a list such as
List<String> runnables = null;
runnables.add("runnable1");
runnables.add("runnable2");
runnables.add("runnable3");
Each of the classes implements Runnable
So for example, this works
Thread t1 = new Thread(new runnable1());
t1.start();
However, what if you want to loop through and run all of them from the array and the array is built dynamically at run time. i.e. you don't know at the time of coding what class names will be in the list as they can change.
runnables.forEach((String classname) -> {
System.out.println("The runnable is " + (String) classname);
Thread t1 = new Thread(new classname());
t1.start();
});
Doesn't work, it says " cannot find symbol symbol: class classname location: class ConncurrencyTesting " On the line that starts "Thread t1 = ...." in the forEach.