I am opening a html page on event in JavaFx Webview and also have a recursive call to same method which also closes the opened webview on another even. In each recursive call I have put a gap of 10 seconds.
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];
}
Issue I am facing here is that initially when jframe is false and code goes through else block, it successfully executes sleep call and execute the recursive call but when showBanner method executes inside if condition which calls the below code.After that My Thread.sleep
call does not return and application gets stucked there.
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;
}
}
Can anyone pointout is there's anything wrong in the above code ?
Thanks,