我有一席之地,需要放弃,以便它能够继续发表带有其他价值的发言。 这样做的最佳方式是什么? 例如:
if (data.startsWith("tcp") )
{
/* main.strings should have a value but it may take a while */
main.start("i generate some encoding/decoding, i take uncertain time...");
int i = 0;
while(main.strings != null)
{
/* Maximum 20 time waiting is accepted, else not */
if (i > 20 ) break;
Thread.sleep(1000);
i++;
}
/* It crash, if main.start() is not creating the main.strings
* so there is a uncertain specific time, for this but we however can t wait long
*/
main.NowUDPSend(main.strings);
...
}
这是在休息期间处理实时问题的最佳途径,这样一来,在20倍的时间里,我就能够离开。