I have a backend server (Jetty) that processes HTTP requests and interacts with a MySQL database.
It is all wired-up with Spring.
I have also a UI front end in Swing that serves as an administrator's tool (the user can interact with the DB etc).
Right now the server and the UI is somewhat bundled, meaning that when the main class starts to load, it first starts the Spring context and then starts the UI (in the EDT thread).
So essentially as long as the UI runs the server is listening for requests.The problem I have is the following:
I would like to show the GUI after the server has been fully initialized and actually I would prefer during the GUI startup to actually connect to the server and get some data, so that they are displayed once the GUI appears on screen.
Right now I achieve this, by adding a sleep of a few seconds before starting to create the GUI in the EDT thread.
This solves it, but the delay is arbitrary and I guess it depends on the target machine. Also it makes the GUI take long time to appear (delay now is 10 seconds).I am trying to figure out the best way to know that Spring context and back-end Jetty has been fully initialized before showing the GUI.
One approach I guess would be try to send a request to the server and if it fails, keep trying for a number of times until it succeeds and then show GUI.
But I was wondering if there is a more standard approach.
Any input is highly welcome. 开发者_JAVA百科
To check whether your Spring application is loaded you can implement Spring's ApplicationListener interface and listen for the ContextRefreshedEvent
If you start Jetty from your Spring context (like in this example), it will be fully initialized once you recieve the ContextRefreshedEvent. If you use some other mechanism to start Jetty you could make a http request to it as the http connector is set up at the end of Jettys startup sequence.
1) create empty GUI with one JButton
for start, second for break of ...
2) Splash Screen or there are I see some implementations by using JWindow/JDialog
then put here one or more JProgressBar that display steped result from ...
3) create SystemTry and display the progress in the trayIcon.displayMessage()
, on the end to display GUI or put here JPopupMenu ...
4) you can created lots of JProgressBars (I created 9 JProgressBars as listening processes with ToolTip) without Borders in one horizontal JPanel (line) in the a_la StatusBar
精彩评论