latch.await java有什么作用,Android系统。 Countdownlatch.await不起作用

我不知道我在这里做错了什么。 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);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值