In J2ME, How to pause and resume the thread

347 Views Asked by At

In my j2me app I have an array of double data type containing 5 coordinates value. This array is inside the thread to continuously check whether the same values is given by GPS.

Once it get correct match, I want to pause the thread then remove match found value from thread and resume the thread. I want this should be happen till array contains coordinates values. Once array got empty I want to pause the thread till it get new value, Once again when array gets values it should start again.

How should I implement this logic in code?

1

There are 1 best solutions below

2
On

If it was me, I wouldn't bother putting the Thread into pause. I'd just have it running all the time.

while (true) {

 for (coordinate in arrayOfCoordinates) {
  if (checkLocation(coordinate)) removeFromArray(coordinate);
 }

try { Thread.sleep(5000); } catch (Exception e) {}

}

I don't see any reason putting the thread into pause, when it's only making such a small check you describe.