gpt4 book ai didi

Java - 如何修正此算法,我不知道 value0 和 value1 何时不为空且为 null

转载 作者:太空宇宙 更新时间:2023-11-04 08:19:00 24 4
gpt4 key购买 nike

如何使这个算法更好并且有效,我总是以reallyFail();结束。而且我不能无限期地让它进入 while 循环,最多只能持续 5 分钟。

// This is a heavy rendering encryption which takes sometimes 1 minute 
// or sometimes
// it takes less then 1 seconds, very random to estimate to a fix time or delay
prepareEncoding(letter);

// Now once that is done i have two values which if null or empty
// Goal can not be accomplished
if (main.myencryption0 != null && main.myencryption1 != null) {
// Once those value are available
// Proceed to he Goal
prepareToGoal(letter);
} else {

// Value is empty or null we do not know the status
// We try for 3 times the same thing
// (i think this is wrong, but could not find alternative best way)
for (int i = 0; main.myencryption0 == null && main.myencryption1 == null && i <= 3; ++i) {
prepareEncoding(letter);
}

// Wait still for few seconds to make 100% sure
// We can not wait more then 5 minute, because its too long.
try {
Thread.sleep(3000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}

// Finally again check same thing do or die
if (main.myencryption0 != null && main.myencryption1 != null) {
prepareToGoal(letter);
} else {
reallyFail(); // OK - give up, drop the ball
}

}

最佳答案

您可以使用 System.currentTimeMillis 检查时间。所以你可以在 5 分钟后离开。

long endTime = System.currentTimeMillis() + 300000; //After 5 min leave while loop

while (System.currentTimeMillis() < endTime
&& main.myencryption0 == null
&& main.myencryption1 == null)
{
prepareEncoding(letter);

try {
Thread.sleep(1);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}

if (main.myencryption0 != null && main.myencryption1 != null) {
prepareToGoal(letter);
} else {
reallyFail(); // OK - give up, drop the ball
}

关于Java - 如何修正此算法,我不知道 value0 和 value1 何时不为空且为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9925928/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com