2014-06-13 2 views
0

나는 두 Parse.com 쿼리를 만들고 있었다 ..CountDownLatch는 두 개의 Parse 쿼리와 함께 사용됩니까?

ABC.findInBackground(new FindCallback<ParseObject>() 
{ 
... 
} 
DEF.findInBackground(new FindCallback<ParseObject>() 
{ 
... 
} 

나는 본질적으로 노력이 일을 물론

CountDownLatch waitForBoth = new CountDownLatch(2); 

ABC.findInBackground(new FindCallback<ParseObject>() 
{ 
... 
waitForBoth.countDown(); 
} 
DEF.findInBackground(new FindCallback<ParseObject>() 
{ 
... 
waitForBoth.countDown(); 
} 
// (error handling (just a flag) not shown) 

waitForBoth.await(); 
Log("both are finished yay!"); 

, 난 그냥 잡다한 오류를 예외 : IllegalMonitorStateException를 얻을 : 스레드에 의해 잠겨 있지 객체 전에() 등 기타

나 이외의 문제는 밀도가 높습니다. 파스의 findInBackground에 대한 호출은 입니다. 사실, 어쨌든 새 스레드에서 벗어나 잖아? 기록을 위해

은, 구문 분석 호출 그 중 하나는, 다음과 같이

ParseQuery<ParseObject>PQ = ParseQuery.getQuery("SomeTable"); 

PQ.whereEqualTo("SomeColumn", ParseUser.getCurrentUser()); 
PQ.include("SomeOtherColumn"); 

PQ.findInBackground(new FindCallback<ParseObject>() 
{ 
@Override 
public void done(List<ParseObject> res, ParseException e) 
    { 
    if (e == null) 
    { 
    // res is the List of ParseObject results from the cloud 
    // here, you'd basically... 
    waitForBoth.countDown(); 
    } 
    else 
    { 
    int errCodeSimple = e.getCode(); 
    exampleWoeFlag = false; 
    waitForBoth.countDown(); 
    } 
    } 
}); 
} 

그에 DOCO 보이는 ...

http://parse.com/docs/android/api/com/parse/ParseQuery.html#findInBackground(com.parse.FindCallback)

답변

1

해석 SDK는 새로운 스레드를 생성하지 , "done"메서드는 UI Thread에서 실행 중입니다. 즉, UI 스레드에서 "countDown"을 호출하고 있음을 의미하지만 사용자가 "대기 중"이라고 했으므로 결코 거기에 도달하지 않습니다.

자신 만의 스레드를 만들고 CountDownLatch를 전달하면 해결할 수 있습니다. 그리고 나서 Parse의 동기식 메서드를 사용하십시오.

이게 맞는가요? 누군가 틀린 Im Im 올바른 경우

그런데 안드로이드의 CountDownLatch에 대해 논의하는 순간 (https://www.coursera.org/course/posa) coursera에서 실행되는 뛰어난 (무료) 코스가 있습니다.

종류의 안부 안동

관련 문제