Discussions
Categories
- 196.8K All Categories
- 2.2K Data
- 238 Big Data Appliance
- 1.9K Data Science
- 450.2K Databases
- 221.7K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 550 MySQL Community Space
- 478 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 544 SQLcl
- 4K SQL Developer Data Modeler
- 187K SQL & PL/SQL
- 21.3K SQL Developer
- 295.8K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.5K Development Tools
- 107 DevOps
- 3.1K QA/Testing
- 646K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 154 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 18 Java Essentials
- 160 Java 8 Questions
- 86K Java Programming
- 80 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 437 LiveLabs
- 38 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 171 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 232 Portuguese
Swing and batch job

Hi,
I have written a java class that takes some considerable time to do what it does.
I want my end user to invoke this, amongst other functionality, from a java swing form.
I have developed my form.
I have used SwingWorker to launch a thread to run my batch job, which works okay.
Without tieing up the form I want the job to run so the user can perform other actions in the form, whilst the batch job is running. I also want the form to check in the background periodically if the batch job has finished successfully, or failed with error. Note my job may run for over an hour, so tieing up the form is not an option....
My problems are; -
The form freezes on launch of the background process
I am not sure if this approach will work with a batch process that does some fairly heavy lifting...
I am not sure if this is the best way to have a 'concurrent request' equivalent
I am using a thread for my batch process but from reading around threads suspect the job may be too 'heavy' for a thread, is there something I would be better using in this case?
Constructive suggestions gratefully received!
Code excerpt as below; -
public void actionPerformed(ActionEvent e){
b.setText("Batch Launched");
b.setEnabled(false);
Progress prog =new Progress();
prog.status ="Launched Daily Backup Routine";
prog.stage=0;
//swing safe thread
SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {
@Override
protected Boolean doInBackground() throws Exception {
// run batch job here
DailyBatch.main(null);
return true;
}
// Can safely update the GUI from this method.
protected void done() {
boolean status;
try {b.setText(prog.status);
// Retrieve the return value of doInBackground.
//think the below is my biggest problem that freezes the form
status = get();
if (status = true){b.setText("Completed backup successfully");
b.setEnabled(true);}
else {b.setText("Backup failed");}
} catch (InterruptedException e) {
// This is thrown if the thread's interrupted.
}
catch (Throwable e) {
// This is thrown if we throw an exception
// from doInBackground.
}
}
Answers
-
There are a few things I have to ask, and forgive me they are very basic, but they need to be asked when I start trouble shooting threads and interaction with the main program.
1 - is your form modal?
2 - do you know how to operate your debugger?
2a - have you run your code using your debugger to see what is happening?
2b - what is the result of running your code in the debugger?
3 - what kind of resource load is presented when this is run?
4 - have you had success in creating and running multi thread applications before?
-
Hi Morgair,
To confirm, I am on the beginner slopes of java.
1. No, not modal - from your comment I have done some reading around modal - this is my problem yes, I need to use jdialog rather than jframe and ensure it is modal?
2. On a site with no java IDE available and tech support which is glacially slow, having to do it all with notepad...
2a / 2b - cf above
3. Light, it is calling actions via an API which then happen in the cloud
4. Multi thread applications yes, fine no problem, but this is my first attempt with swing
thanks for your input,
Robert.
-
Robert,
No, I do not believe you need to use a JFrame as modal. If I understand correctly, you want to click buttons on your GUI and have it launch processes, and periodically you want it to check to see if those processes are complete; I do not see where a modal dialog would be best for that.
-
If you can, I suggest you download an IDE with an integrated debugger, like NetBeans, and install it yourself if you have rights on the local box to do so. Using a debugger can really make a world of difference.
The JDK used to come with a stand alone debugger, it may still do so, check your version and see if it does. If you can get it working for you, that might be your quickest route to seeing the problem, and ultimately finding the solution.
-
Hi,
The community version of IntelliJ from jetbrains in zip version can be used even if you do not have admin rights to install things. For swing based development, this should be sufficient.
https://www.jetbrains.com/idea/download/download-thanks.html?platform=windowsZip&code=IIC
HTH.
-
Yes, essentially the form serves as a switchboard for the user to launch long running jobs, which run in threads, and then I want the form (without freezing) to monitor the threads and report their ongoing progress back to the user.
-
Thanks, appreciated, I will give this a go!
-
FYI,
off topic:
There is a Java MOOC just started, just thought of passing the message in case if you are not aware of it ...