How to run Appium scripts in parallel based on methods

I am trying to run test methods parallel in Appium+testNG on different devices. It works for me when I run test methods parallel based on classes ie parallel=classes.

But same is not working when I try to run test methods parallel based on methods ie parallel=methods. I am using below code to run parallel.

@BeforeMethod(alwaysRun = true)
public void setdeviceName() throws Exception {
if (ConfigUtil.getConfigDetails().split("::")[1].equalsIgnoreCase(“device”)) {
synchronized (DeviceEmuList) {
deviceName = DeviceEmuList.get(0);
System.out.println("###########This is the device name###############" + deviceName);
DeviceEmuList.remove(0);
port = Integer.parseInt((String) portList.get(0));
portList.remove(0);

            System.out.println("inside setup" + deviceName + port);

            driver = new DriverManager().getdriver(new Object[] { deviceName, port });

        }
    }

}

@AfterMethod(alwaysRun = true)
public void takeSS() {
    driver.quit();
    DeviceEmuList.add(this.deviceName);
    portList.add(String.valueOf(this.port));
}
When I use above code, then app launches on first device then on second device and all test methods run only on second device. None of the test methods are running on first device. This looks like i am running test methods serially on second device.

Same logic works fine when I am creating driver in @BeforeClass.

Appium actually doesn’t control any of the TestNg framework. In other words, there isn’t anything you can do in Appium that will affect how these tests run. It seems more of a TestNg specific question. You may get lucky and get a good answer here, but I would think you might have better luck in the TestNg Google Group, which is the official TestNg discussion forum:

https://groups.google.com/forum/#!forum/testng-users