【发布时间】:2015-07-01 14:04:44
【问题描述】:
给定的代码在 doInBackground() 中工作。 while 循环总是正确的,但我不知道它如何在 catch 中调用其他方法。
谁能解释一下这项技术以及我们如何从这项技术中受益。我不知道我们如何以及何时摆脱困境。
doInBackground
if(isRunning)
{
while (true) //this loop should run always.
{
try
{
Thread.sleep(1L);
}
catch (InterruptedException ex)
{
Log.e("Testing Interuption", "error=" + ex.getMessage());
// some working here is also running
}
}
}
它可以在while之后调用任何语句吗?我的意思是它是否也可以退出while循环。
编辑
Interuption 是什么时候发生的。这意味着当另一个 AsyncTask 正在调用 Thread.sleep();它会中断(意味着去赶上)。我说的对吗?
我正在调用Multiple AsyncTasks 来设置CameraPreview using Bitmap。
@TargetApi(11)
public void start()
{
if (Build.VERSION.SDK_INT >= 11)
{
executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
return;
}
execute(new Void[0]);
}
【问题讨论】:
标签: java android multithreading exception