Using unique appium servers and ports, but still getting "java.lang.IllegalThreadStateException: Thread already started"

Hello,

I have tried everything, but I still randomly get java.lang.IllegalThreadStateException: Thread already started" errors when running multiple appium test runs on two different physical android devices in parallel.

I have tried launching like this:

node /usr/local/bin/appium -a ${APPIUM_NODE} -cp ${UNIQUE_CALLBACK_PORT} -p ${UNIQUE_PORT} -bp ${UNIQUE_BOOT_PORT}>appium.log 2>&1 &

Where APPIUM_NODE is the ip address for the new appium server to use, “127.0.0.1” is what I am using for both runs, because appium fails to connect to any other port I try to enter.

UNIQUE_CALLBACK_PORT is unique between the two devices: 1234 and 1235
UNIQUE_PORT is unique between the two devices: 4723 and 4733
UNIQUE_BOOT_PORT is unique between the two devices: 2251 and 2261

I noticed that -U is deprecated, so now I supply the UDID’s of the two devices via the desired capability.

I also tried just running “appium” as the command, rather than “node /…/appium”

No matter what I do, these “thread already started” errors randomly occur and kill the runs if I run them in parallel!

Appium v1.6.3

Thanks for any help.

Also, much of the time, when there is not a java failure, one device sits and does nothing until the other device is completed its run. But I have done everything appium suggests I must do to make them run separately…

I am running them off of a MacBookPro, Sierra. Our application is a Native app.

I finally got almost everything working. I setup Selenium Grid and it works.

However, I still transiently get “Thread already started” errors. I have no idea what is going on. I kill all appium processes before I start a new one…

I fixed this issue by directly downloading the newest UiAutomator2-server from github. The version installed when downloading via npm install -g Appium is NOT the newest server, and the newest server has a fix for this exact issue. Since replacing it, I have not had this error occur again.