java - Loop in JavaFX-Launcher preventing JavaFX application thread from starting -
if put endless loop in javafx-launcher thread
, application never start. know runs on different thread
, why happen?
just create new project , override init()
, add forever loop.
// mine not forever boolean go = true; @override public void init() throws exception { // todo auto-generated method stub super.init(); // 'while' comes after line while(go){} // comment guy , ayt } @override public void stop() throws exception { // todo auto-generated method stub go = false; super.stop(); }
does mean javafx-launcher thread
should exit before application ui can start -(i.e javafxapplication thread), or missing something?
if javafx-launcher
should alternative launching application needs before app starts, why can't concurrent, because if want in successions place code before super.init()
method?
direct explanation of happening
the documentation application start method explicitly states happening:
the start method called after init method has returned, , after system ready application begin running.
so, if run infinite loop in init method never returns, application never start.
further documentation on application lifecycle in application javadoc.
some asides, speculation , possibly related info
the following information may or may not relevant issue @ hand.
i believe idea behind init method can put logic in init method can execute while javafx system initialized. initialization of javafx system takes amount of time, though on modern processing system not expect long amount of time (e.g. less second).
most javafx application have seen not make use of init method.
if initialization lengthy , want application start before initialization complete, need explicit logic handle that.
for instance, create javafx task in init method runs on it's own thread. perform initialization there. in start method display ui immediately, limited functionality. once initialization complete (which can known listener on status of initialization task), enable functional ui depends on data initialization being available. although not quite same (as running of task logic start rather init), similar example of approach in gist sample, "displays javafx splash page intensive startup task progress monitoring".
javafx have concept of preloader provides in-built framework handling lengthy initialization, haven't seen used. preloader targeted @ java embedded in web page via plugin or java web start. these not technologies used in combination javafx. javafx applications standalone applications not relying on web page plugins or web start execution). use preloader framework initializing application (even if works in standalone mode), simpler use task purpose. further information on preloader usage, can refer to: how use javafx preloader stand-alone application in eclipse? (note answer not specific eclipse though question is).
Comments
Post a Comment