Idle Instances
This feature allows you to define a number of instances (sessions) to be started before user requests to start a new instance. The purpose of idle instances is to reduce the time user has to wait for the JVM startup. You can configure how many idle instances should be available at all times in app config in Admin Console. Note that idle instance is application specific.
You can see a list of currently running idle instances in Sessions view.
When you change your app's configuration, idle instances are automatically recreated.
Pre-launch
There are multiple ways to configure Idle application launch of a Desktop application. In Webswing app configuration next to Desktop Launcher Type you can find field called Pre-launch
. This field has 3 options.
NONE
The launch of idle instance stops right before calling the main class defined in the app launch configuration. The main class of your app will be called after the user requests a new instance.
CUSTOM
This option allows you to do pre-launch task(s) inside a custom class. The launch of idle instance stops after this call and before the main class defined in the app launch configuration (full main). You can do any kind of initialization you need to speed-up the startup of the full main, for example loading backend services.
The custom pre-launch class must extend org.webswing.toolkit.api.lifecycle.WebswingPrelaunch
and after the work is done you must call prelaunchDone()
method. This signalizes Webswing that instance is fully pre-launched and it may be used for user connections.
MAIN_CLASS
This option launches the idle instance fully including calling the main class defined in app launch configuration. When user requests a new instance, the instance will be instantly ready to be used. Note there are restrictions for this option, read below.
InvokeWhenLaunched
When you configure a MAIN_CLASS pre-launch of Idle instances your app main starts before the user is ready to receive any rendering frames. In most cases it is preferred that the UI shows only after the instance is fully launched (right before a user connects to the instance). There might also be other tasks or processes that should be deferred until the instance is ready. To help with this Webswing provides API method WebswingUtil.getWebswingApi().invokeWhenLaunched(Runnable)
. You provide a callback to be called right after the instance is launched (i.e. the final stage when it is ready to be connected with user). The callback will be called regardless of whether it is an idle instance or not. It is recommended to initiate the UI from this callback. Note that the callback is not run on EDT, so you should call SwingUtilities.invokeLater()
when working with UI.
Restrictions
There are some restrictions for usage of idle instances. Since the idle instance is started before user requests the instance, it is not possible to use user supplied variables in the following configuration parameters:
- userDir
- javaFxClassPathEntries
- javaVersion
- jreExecutable
- vmArgs
- classPathEntries
- sessionLogFileSize
- sessionLogMaxFileSize
If you have any user supplied variables during an idle instance startup, you will see a warning in logs, which tells you which variable could not be replaced so that you can fix it.
If you need user supplied data to be available as system properties during the call of your main class, please use launcherSystemProperties
configuration property in app config.
If you are using MAIN_CLASS option for Pre-launch, it is not possible to use any user supplied variable during the instance launch. If you need to send user supplied data to an already fully pre-launched idle instance please use JsLinkDirect.
Cluster
In cluster environment the number of idle instances configured applies to a session pool. If you configure 3 idle instances, every session pool will create 3 idle instances. If you want to restrict the number of idle instances for a session pool, you can change the value of sessionpool.instances.maxIdle
parameter in webswing-sessionpool.properties
. You can also disable idle instances for a specific session pool with sessionpool.idleAllowed
parameter.
You can see the number of idle sessions running in session pool in Overview.