我的Parse.com查询太慢,下面的代码是1个网络通话。因此,我想并行执行3个查询:
这是当前的代码:
public static void readBusShelters() {
ParseQuery<ParseObject> query = ParseQuery.getQuery(BusShelter.TABLE_NAME);
query.setLimit(500);
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> list, ParseException e) {
}
});
}
非常感谢一些帮助!
答案 0 :(得分:1)
使用回调在PShape myshape;
import peasy.test.*;
import peasy.org.apache.commons.math.*;
import peasy.*;
import peasy.org.apache.commons.math.geometry.*;
PeasyCam camera;
void setup(){
size( 640, 480, P3D);
camera = new PeasyCam(this, 0, 0, 0, 50);
frameRate(10);
myshape = loadShape("test.obj");
for (int i = 0; i < myshape.getVertexCount(); i++){
PVector v = myshape.getVertex(i);
println("Inside");
v.x *= 45;
v.y *= 45;
v.z *= 45;
myshape.setVertex(i, v);
}
}
void draw(){
background(0);
shape(myshape);
}
中包装解析查询并在线程池上执行以使任务能够并行运行。
示例:
AsyncTask
回调:
public class MainActivity extends AppCompatActivity implements OnTaskCompleted {
@Override
public void onTaskCompleted(List<ParseObject> response) {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
new FetchParseQueryTask(MainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new PagingOptions(0, 200));
new FetchParseQueryTask(MainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new PagingOptions(1, 200));
new FetchParseQueryTask(MainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new PagingOptions(2, 200));
}
}
public interface OnTaskCompleted {
void onTaskCompleted(List<ParseObject> response);
}
类的示例实现:
FetchParseQueryTask
public class FetchParseQueryTask extends AsyncTask<PagingOptions, Void, List<ParseObject>> {
private OnTaskCompleted mTaskCompleted;
public FetchParseQueryTask(OnTaskCompleted activityContext){
mTaskCompleted = activityContext;
}
@Override
protected List<ParseObject> doInBackground(PagingOptions... params) {
PagingOptions pagingOptions = params[0];
ParseQuery<ParseObject> query = ParseQuery.getQuery("TABLE_NAME");
query.setLimit(pagingOptions.getLimit());
query.setSkip(pagingOptions.getPage() * pagingOptions.getLimit());
try {
return query.find();
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(List<ParseObject> result) {
super.onPostExecute(result);
if (mTaskCompleted != null) {
mTaskCompleted.onTaskCompleted(result);
}
}
}
上课:
PagingOptions