我在 JavaFx Webview 中打开一个关于事件的 html 页面,并且还对同一方法进行了递归调用,该方法也关闭了另一个甚至打开的 webview。在每个递归调用中,我都设置了 10 秒的间隔。
private static void checkForAPIStatus(String[] args) {
System.out.println("checkForAPIStatus method started....");
if (RandomStringFromArray().equals("Unsatisfactory")) {
if (jframe == false) {
if (checkForTransactionStatus().equals("END TICKET ")) {
BringUpFrame.showBanner(args);
jframe = true;
}
}
} else {
if (jframe == true) {
BringUpFrame.disposeBanner();
}
jframe = false;
}
System.out.println(jframe);
try {
System.out.println("Before sleep");
Thread.sleep(TimeInterval);
System.out.println("After sleep");
} catch (InterruptedException e) {
e.printStackTrace();
}
checkForAPIStatus(args);
}
public static String RandomStringFromArray() {
String[] arr = {"Unsatisfactory", "Ok"};
Random r = new Random();
int randomNumber = r.nextInt(arr.length);
System.out.println(arr[randomNumber]);
return arr[randomNumber];
}
我在这里面临的问题是,最初当 jframe 为 false 并且代码通过 else 块时,它成功执行睡眠调用并执行递归调用,但是当 showBanner 方法在调用以下代码的 if 条件内执行时。之后我的Thread.sleep
调用不返回并且应用程序被卡在那里。
public class BringUpFrame extends Application{
static Logger logger = LoggerFactory.getLogger(BringUpFrame.class);
private static Stage stage;
@Override
public void start(Stage primaryStage) throws Exception {
int width = 0;
int height = 0;
String ScrnResol = getScreenResolution();
String[] ScreenResolution = ScrnResol.split(",");
try {
width = Integer.parseInt(ScreenResolution[0]);
height = Integer.parseInt(ScreenResolution[1]);
} catch (NumberFormatException nfe) {
logger.info("NumberFormatException: " + nfe.getMessage());
}
WebView webView = new WebView();
WebEngine webEngine = webView.getEngine();
URL resource = getClass().getClassLoader().getResource("test.htm");
System.out.println("Resource before load "+resource);
webEngine.load( resource.toString() );
Scene scene = new Scene(webView,width,height);
primaryStage.setScene(scene);
primaryStage.setAlwaysOnTop(true);
primaryStage.setFullScreen(true);
primaryStage.setFullScreenExitHint("");
primaryStage.show();
stage = primaryStage;
}
public static void showBanner(String[] args) throws IOException {
launch(args);
}
public static void disposeBanner() {
stage.close();
}
public static String getScreenResolution() {
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int width = gd.getDisplayMode().getWidth();
int height = gd.getDisplayMode().getHeight();
String resolution = width + "," + height;
logger.info("Till Resolution is (width,height) : " + resolution);
return resolution;
}
}
谁能指出上面的代码有什么问题吗?
谢谢,