Fix Thread.sleep Usage

This commit is contained in:
Konloch 2024-08-21 09:41:51 -06:00
parent e138680d7c
commit de433f6d84

AI 샘플 코드 생성 중입니다

Loading...
4 changed files with 30 additions and 25 deletions

View File

@ -22,6 +22,7 @@ import the.bytecode.club.bytecodeviewer.plugin.preinstalled.EZInjection;
import the.bytecode.club.bytecodeviewer.util.DialogUtils; import the.bytecode.club.bytecodeviewer.util.DialogUtils;
import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.JarUtils;
import the.bytecode.club.bytecodeviewer.util.MiscUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils;
import the.bytecode.club.bytecodeviewer.util.SleepUtil;
import static the.bytecode.club.bytecodeviewer.Constants.DEV_MODE; import static the.bytecode.club.bytecodeviewer.Constants.DEV_MODE;
import static the.bytecode.club.bytecodeviewer.Constants.fs; import static the.bytecode.club.bytecodeviewer.Constants.fs;
@ -290,14 +291,9 @@ public class BCV
*/ */
public static void hideFrame(JFrame frame, long milliseconds) public static void hideFrame(JFrame frame, long milliseconds)
{ {
new Thread(()->{ new Thread(()->
long started = System.currentTimeMillis(); {
while(System.currentTimeMillis()-started <= milliseconds) SleepUtil.sleep(milliseconds);
{
try {
Thread.sleep(100);
} catch (InterruptedException ignored) { }
}
frame.setVisible(false); frame.setVisible(false);
}, "Timed Swing Hide").start(); }, "Timed Swing Hide").start();

View File

@ -13,6 +13,7 @@ import the.bytecode.club.bytecodeviewer.resources.ExternalResources;
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.JarUtils;
import the.bytecode.club.bytecodeviewer.util.MiscUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils;
import the.bytecode.club.bytecodeviewer.util.SleepUtil;
import static the.bytecode.club.bytecodeviewer.Constants.fs; import static the.bytecode.club.bytecodeviewer.Constants.fs;
import static the.bytecode.club.bytecodeviewer.Constants.nl; import static the.bytecode.club.bytecodeviewer.Constants.nl;
@ -95,15 +96,10 @@ public class JavaCompiler extends InternalCompiler
Process process = pb.start(); Process process = pb.start();
BytecodeViewer.createdProcesses.add(process); BytecodeViewer.createdProcesses.add(process);
Thread failSafe = new Thread(() -> { Thread failSafe = new Thread(() ->
long started = System.currentTimeMillis(); {
while (System.currentTimeMillis() - started <= 10_000) { //wait 10 seconds
try { SleepUtil.sleep(10_000);
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (process.isAlive()) if (process.isAlive())
{ {

View File

@ -47,15 +47,8 @@ public class BootCheck implements Runnable
@Override @Override
public void run() public void run()
{ {
long start = System.currentTimeMillis();
//7 second failsafe //7 second failsafe
while (System.currentTimeMillis() - start < 7000) SleepUtil.sleep(7000);
{
try {
Thread.sleep(100);
} catch (InterruptedException ignored) { }
}
//if it's failed to boot and it's not downloading attempt to load the libraries //if it's failed to boot and it's not downloading attempt to load the libraries
failSafeLoadLibraries(); failSafeLoadLibraries();

View File

@ -0,0 +1,20 @@
package the.bytecode.club.bytecodeviewer.util;
/**
* @author Konloch
* @since 8/21/2024
*/
public class SleepUtil
{
public static void sleep(long ms)
{
try
{
Thread.sleep(ms);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}