i am trying to invoke run() method of Runnable objects and i can't understand why it doesn't work. the purpose of this is to create set of various Runnable objects and add it Set, then to invoke all of them at once with their run() method. can you please help me to understand what am i doing wrong?
here is my code:
public class WebDriverThreadsManager
{
private int numOfFireFoxThreads = 0;
private Set<Runnable> webDriversSet = new HashSet<Runnable>();
public WebDriverThreadsManager(){}
public void addWebDriversToSeperateThreadsSet(String i_NameOfBrowser) throws ClassNotFoundException, InstantiationException, IllegalAccessException
{
Class cls;
switch (i_NameOfBrowser)
{
case "FireFox":
{
cls = Class.forName("SeleniumLerning.ThreadedFireFoxWebDriver");
numOfInstancesToAddToThreadsSet(cls,this.getNumOfFireFoxThreads());
}
default:
throw new IllegalStateException("Unknown Browser");
}
private void numOfInstancesToAddToThreadsSet(Class cls, int numOfInsances) throws InstantiationException, IllegalAccessException
{
for(int i=0 ; i < numOfInsances ; i++)
{
Object obj = cls.newInstance();
this.webDriversSet.add((Runnable)obj);
}
}
public void invokeWebDrivers()
{
Iterator iter = this.webDriversSet.iterator();
//Method method;
while (iter.hasNext())
{
try
{
Method method = iter.getClass().getDeclaredMethod("run");
method.invoke(iter.getClass());
}
catch (NoSuchMethodException ex)
{
Logger.getLogger(WebDriverThreadsManager.class.getName()).log(Level.SEVERE, null, ex);
}
catch (SecurityException ex)
{
Logger.getLogger(WebDriverThreadsManager.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(WebDriverThreadsManager.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalArgumentException ex) {
Logger.getLogger(WebDriverThreadsManager.class.getName()).log(Level.SEVERE, null, ex);
} catch (InvocationTargetException ex) {
Logger.getLogger(WebDriverThreadsManager.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
public void Main()
{
public static void main(String args[])
{
WebDriverThreadsManager manager = new WebDriverThreadsManager();
manager.setNumOfFireFoxThreads(5);
addWebDriversToSeperateThreadsSet("FireFox");
invokeWebDrivers();
}
}
Aucun commentaire:
Enregistrer un commentaire