wait or sleep or something
A numerical time value (not shown here) is available to this method in real time, that could conceivably be used to place a temporary hold on the following stop from being carried out:
public void stopRec(){
audioRecord.stop();
try {
dos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Let's say a time forward has commenced and we're now t=0.25 into the ellapsed count. But user is moving to invoke the above now, and I want to prevent that underlying method from transpiring until t>0.5 into the count.
It's fine if the user wants to (and does) press the close button, go ahead开发者_如何学JAVA, and I'll throw a wait message on screen that will say more or less "Fine, stopping...." But the thing won't actually stop until >0.5 occurs behind the scenes.
How would a wait statement (I wouldn't imagine a loop would be good because of wasted CPU cycles) be used in the above scenario? Thanks for any help.
One way is to schedule a delay task of stop using ScheduledExecutorService.
精彩评论