我不知道我在这里做错了什么。 Countdownlatch.await不起作用。绝对没有等待时间。我已经测试了荒谬的数字(50秒),并且有紧接着后来的电话。我试图在UI线程上使用它。我还有另一个线程正在运行。
代码:
private final CountDownLatch latch = new CountDownLatch(1); //called earlier
void someMethod() {
//code
Runnable flashScreen = new Runnable() {
@Override
public void run() {
flashScreen();
}
};
runOnUiThread(flashScreen);
//Mode code
}
private void flashScreen()
{
final TextView monthDayYear = (TextView)findViewById(R.id.month_day_year);
final TextView hourMinuteSecond = (TextView)findViewById(R.id.hour_minute_second);
//Get date and time
final SyncModule syncModule = _application.getSyncModule();
syncModule.start();
while(counter.intValue() < 150) {
try {
//Thread.sleep(10);
latch.countDown();
latch.await(10, TimeUnit.MILLISECONDS);
counter.incrementAndGet();
} catch (InterruptedException ex) {
Util.appendLog("SyncActivity: InterruptedException while flashing camera " + ex.getMessage());
}
}
final ImageView fadeView = (ImageView)findViewById(R.id.sync_flash_rectangle);
fadeView.setBackgroundColor(Color.WHITE);
fadeIn(fadeView, 1, 0, 1000, true);
Calendar syncTime = syncModule.getDateAndTime();
monthDayYear.setText(new SimpleDateFormat("MM/dd/yyyy").format(syncTime.getTime()));
hourMinuteSecond.setText(new SimpleDateFormat("HH:mm:ss:00").format(syncTime.getTime()));
try {
latch.countDown();
latch.await(50, TimeUnit.SECONDS);
} catch (InterruptedException ex) {
Util.appendLog("SyncActivity: InterruptedException while flashing camera " + ex.getMessage());
}
counter.set(1000);
}