1

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?

4

1 回答 1

0

如果是我,我不会费心让线程暂停。我只是让它一直运行。

while (true) {

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

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

}

我看不出有什么理由让线程暂停,因为它只进行了你描述的这么小的检查。

于 2013-03-24T06:17:30.060 回答