Implement a Execution Log in Java - java

Coming from a WPF world, I am having a hard time implementing some basic stuff in Java.
I need to execute a *.JAR file from another java GUI application. This JAR file takes minutes to finish, and I want the GUI not to freeze.
So, my initial solution would be: create a SwingWorker class to call a command line in background.
My main concerns are:
I need to get the console output from the *.JAR file and show it in the GUI. Is it possible to update the GUI from a background thread?
Is it possible to cancel the thread from a user input?
How do I get notified that the thread is finished?
Is my solution a good one?

Related

How can i allow three threads accessing three different consoles in java?

So i am trying to build a simple application to show concurrency in java. I wanna open 3 console windows so that i can get input output from all of them. How can do this?
Edit:I have 3 threads, each thread has its own set of cache. I wanna run 3 consoles separately in java.
i opened command prompt using Runtime class and tried attaching input and outputstream to it. But failed writing or reading from that newly opened console.
In most OSes, a process can open only one console.
You could create multiple processes and communicate between them, but that would show interprocess communication rather than inter-thread communication.
On Windows, you could try spawning child processes using 'more' or 'copy con' commands and writing to their input stream, or run your own java client which just echos input to output.
You could also create multiple JFrames and record the output of the threads in them, but again a given process has to do all its swing updates in the one swing thread, so the different threads have to sync when they output.
You're probably better off writing to the same console with different prefixes; output to the screen is always going to be a single thread in current OSes.

Which thread for non-GUI graphics?

For the first time, I'm writing a Java application that is graphics-intensive without a GUI. It generates images by creating a BufferedImage and working with its Graphics2D object. Images are written to files using ImageIO.write.
I need to decide whether to work in the main thread, or the Event Dispatch Thread.
In favor of the EDT, I would do all the graphics updates in the EDT if I were writing a GUI.
In favor of the main thread, the application will compute continuously for the whole time it is running, without any user interaction to break things up.
Which thread for non-GUI graphics?
Non EDT is what I would have guessed (and the way I've always coded it).
But could you confirm, does the app. have a GUI?
No, the app does not have a GUI. It needs to be able to run unattended.
That settles it, forget the EDT & use whatever Thread you like (including the default one given to the app.).

My Jframe Freezes When I start a process

i build a process for run an exe file from java app so run with start() then my frame freezes. It's just becoming a picture. I can't even close it with X. When i minimize the frame and open it again i see darkness in frame. My threads running in background, i can see from output but why my frame freezes?
i build a process for run an exe file from java app so run with start() then my frame freezes
Probably because you start the process on the Event Dispatch Thread and the process is blocking the Thread which means the GUI can't respond to events or repaint itself.
The process should be started in a separate Thread. Read the section from the Swing tutorial on Concurrency for more information.
Could you provide some code, the problem could be a number of issues so it would help cut down on some of them.
I would suggest checking that you haven't suspended/slept any of your threads.

Automating interaction with a closed-sourced Windows XP GUI-based Program

I've a closed-sourced Windows XP GUI-based that performs some measurements.
My current manual workflow is:
Start the data capture by clicking on the "Run" button on the GUI
Stop the data capture by pressing the "Stop" button on the GUI.
Read some value displayed on the screen.
Save the data for the session to a file.
There is no library or API to automate this whole interaction and therefore I've no option but to do it manually :( and I'm sick of it !
As you clearly see that this approach is not only time-consuming but also error prone because it is limited by my reaction time which varies with every run.
I was wondering if there is a way to automate this interaction? If yes, what are my options? I would prefer to implement something in Python or Java. But I'm open to other options as well.
My idea is to implement a server process that runs on the Windows XP machine. I can then remotely send requests to this server process which in turn will execute my workflow automatically.
There's an amazing windows GUI automation tool called autoit. http://www.autoitscript.com/site/autoit/
You asked about linking AutoIt with Java. For my purposes, I've done this using a ProcessBuilder to create a Process, then get the Processes InputStream and ErrorStream and be sure to handle these streams in a separate thread. I have AutoIt communicate with my Java program using the InputStream. A good article for this (though a little out of date) is this one: When Runtime.exec() won't. It is key to be sure that the process be run on a background thread and that the two streams be read in their own threads. If you're doing this in a Swing GUI, then extra care must be taken that all Swing calls be made on the main Swing event thread, the EDT.

Is it possible to run a batch file within a JFace wizard with progress monitor?

I want to run a batch script from within my JFace wizard, and even I want to show the progress monitor for that within the wizard.
Why I want this because, when I run a batch script within my java code, the control on batch script execution gets lost from java code. That's why I'm thinking whether is it possible to run this within the wizard so that I should have the control.
Reagrds,
Anand
You need to be able to measure the script's progress somehow.
For example, if the script could log its progress to the file, then a thread in your application could read it and pass to the progress monitor (by calling IProgressMonitor#worked(valueFromFile))

Categories

Resources