I am using Scripting for Java in JDK 6 on Win7 to build Swing GUIs and I am trying to determine the best means to emulate a typical Java execution environment when launching a script with the JDK\bin\jrunscript.exe program. I have the following file extension and association set up in my environment.
assoc .jsx=JSXFile ftype JSXFile=c:\jdk6\bin\jrunscript "%1" %*
Some of the scripts to be created may perform lengthy and potentially blocking I/O operations and I do not want to lock up the UI during those operations. The first approach used the following code to invoke the app with SwingUtilities. However, when passing in a script to jrunscript as a command line parameter, the script flashes a brief glimpse of the UI and then terminates immediately.
importPackage(javax.swing)
var runMyApp = new java.lang.Runnable(){
run: function(){
var frame = JFrame("This REALLY is 'Java Script' :)")
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
frame.setSize(640,480)
frame.setLocation(200,200)
frame.setVisible(true)
}
};
SwingUtilities.invokeLater(runMyApp)
I then added the following immediately after the "SwingUtilities.invokeLater..." statement and the GUI did stay running.
var dummyThread = new java.lang.Thread("DUMMY_THREAD")
dummyThread.start()
while(1){
dummyThread.sleep(1000)
}
I am still new to scripting with Java (I do using Jython on regular basis though), and I am wondering if creating the dummy thread is the best means to prevent the script from terminating immediately, or if there is a solution I am missing completely.