java - How to terminate a scheduled thread when JavaFX Runtime exits? -
i'm looking on similar examples problem. have javafx app runs gui updates via thread running from: scheduledexecutorservice::scheduleatfixedrate.
this similar couple of other questions. 2 recognised situation these:
the question need resolve, however, next step. target embedded application , there's no opportunity manually kill jvm-task, or other easy answers, etc. i'm afraid reboot reserved critically-serious.
we need ensure threads closed off in orderly way. i'm looking kind of call or event lets me register clean-up routine close-down stuff?
i thinking there ought 'something' in base class, javafx javafx.application.application deed.
is stop method might use or can register called when there stop fxmlcontroller?
at present when run javafx app netbeans, jvm process persists. stops further build scripts , locks jar file. netbeans gives option kill task. true solution means application/jvm closes-down orderly , neatly.
(update) ... looked javafx.application class use launch javafx app. implemented stop() method. here make sure i've called platform.exit() ...
///// // @see // -- http://docs.oracle.com/javafx/2/api/javafx/application/application.html#stop%28%29 // public void stop() { platform.exit(); }
this doesn't cure problem when running netbeans. need click stop [x] button 2 times, process stop when use kill button. if interested in progress reported bug: [bug 245284], there's small clock example demonstrate problem. when close window, netbeans process running panel still 'running'. can't build because jar file locked. @ least know manually kill development program.
- suggestions welcome . . .
i have partial solution cover fellow developers caught in situation. declare stop() method in in javafx app (called "mainapp" netbeans maven javafx template). there questions of course, first method.
- see: javafx application
stop called @ end of program. had call call platform.exit() close-down javafx runtime. i've added call shutdown other active executor threads, kept in list now, test solution.
public class mainapp extends application { @override public void start(stage stage) throws exception { ..... } /** * close down application * @see * -- http://docs.oracle.com/javafx/2/api/javafx/application/application.html#stop%28%29 **/ @override public void stop() { platform.exit(); for( scheduledexecutorservice sched : activeexecutorservices ) { sched.shutdown(); } } }//mainappl class
so commenting-out call shutdown , running javafx program, application finishes won't exit, , netbeans show running task. need manually click on kill-button in netbeans.
uncomment shutdown() call. when javafx application exits, dissappears netbeans running jobs. appears resolotion.
the remaining questions:
- what correct order between platform.exit() , shutdown()?
- with more 1 scheduledexecutorservice matter order used shut them-off? lifo or fifo?
- is there better way?
- ought netbeans able detect 'process overrun' , report problem. @ least leave , option ignore or fix program.
hopefyully assist next faces similar problem :-)
Comments
Post a Comment