Action is performing twice in parallel tesing

Im trying to execute parallel testing for android using Testng. It working but the action are performing twice.

Example:
I created a simple android login application
Im trying to pass username and password, but it is passing twice.
if password is test it is passing as “testtest”.

Below is my sample code:

package Appium;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import com.beust.jcommander.Parameter;

public class Appium {
WebDriver driver;

@Parameters({"deviceName_","UDID_","platformVersion_","URL_"})
@BeforeTest
public void setup(String deviceName_, String UDID_, String platformVersion_, String URL_) throws MalformedURLException {
	File appDir = new File(System.getProperty("user.dir")+ "/Apps");
    File app = new File(appDir, "app-debug.apk");
	// Created object of DesiredCapabilities class.
	DesiredCapabilities capabilities = new DesiredCapabilities();

	// Set android deviceName desired capability. Set your device name.
	capabilities.setCapability("deviceName", deviceName_);

	// Set BROWSER_NAME desired capability. It's Android in our case here.
	capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");

	// Set android VERSION desired capability. Set your mobile device's OS
	// version.
	capabilities.setCapability("platformVersion", platformVersion_);

	// Set android platformName desired capability. It's Android in our case
	// here.
	capabilities.setCapability("platformName", "Android");
	capabilities.setCapability("udid", UDID_);

	// Set android appPackage desired capability. It is
	// com.android.calculator2 for calculator application.
	// Set your application's appPackage if you are using any other app.
	capabilities.setCapability("appPackage", "com.example.android.logindemo");

	// Set android appActivity desired capability. It is
	// com.android.calculator2.Calculator for calculator application.
	// Set your application's appPackage if you are using any other app.
	capabilities.setCapability("appActivity", "com.example.android.logindemo.MainActivity");
	
	capabilities.setCapability("app", app.getAbsolutePath());

	// Created object of RemoteWebDriver will all set capabilities.
	// Set appium server address and port number in URL string.
	// It will launch calculator app in android device.
	driver = new RemoteWebDriver(new URL("http://"+URL_), capabilities);
	driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}

@Test
public void test() {
	driver.findElement(By.id("com.example.android.logindemo:id/etName")).sendKeys("****");
	driver.findElement(By.id("com.example.android.logindemo:id/etPassword")).sendKeys("****");
	driver.findElement(By.id("com.example.android.logindemo:id/btnLogin")).click();
}

}

Testng.xml:

<?xml version="1.0" encoding="UTF-8"?>

Have you mentioned 2 device names??

ya in xml i mentioned device one and device two

Please try this

@DataProvider(parallel=true)
public Object[][] portDriver()
{
//Rows - Number of times your test has to be repeated.
//Columns - Number of parameters in test data.
Object[][] data = new Object[2][1];

	// 1st row
	data[0][0] ="5d6ef2bd";
	// 2nd row
	data[1][0] ="d859dc2d";
	return data;
	}

	
	public static String firstDeviceName="5d6ef2bd";
	public static String SecondDeviceName="d859dc2d";


		
		@Factory(dataProvider="portDriver")
		@BeforeClass
		public void Init(String device_id) throws IOException, InterruptedException{
			DesiredCapabilities capabilities = new DesiredCapabilities();
			if(device_id.equalsIgnoreCase(firstDeviceName)){	
				capabilities.setCapability("deviceName",firstDeviceName);
				capabilities.setCapability("udid", firstDeviceName);
				capabilities.setCapability(MobileCapabilityType.APP,"xyz.apk");
				//setDeviceID=device_id;
				driver1=new AndroidDriver(new URL("http://127.0.0.1:4733/wd/hub"), capabilities);
		        driver1.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
		      
				
			}else if(device_id.equalsIgnoreCase(SecondDeviceName)){
				
				capabilities.setCapability("deviceName",SecondDeviceName);
				capabilities.setCapability("udid", SecondDeviceName);
				capabilities.setCapability(MobileCapabilityType.APP,xyz.apk");
				driver2=new AndroidDriver(new URL("http://127.0.0.1:4743/wd/hub"), capabilities);
		        driver2.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);			      
				
			}
	}

Here @Ajinkya you are using two drivers driver1 and driver2. For performing test whether i want to write separate scripts for each devices?

@hemachandran_R.S need parallel -> start from changing driver to local thread variable first.

a little to read more - https://rationaleemotions.wordpress.com/2013/07/31/parallel-webdriver-executions-using-testng/