it sounds like you are passing the current thread to the second process
rather than instantiating a seperate thread and letting it loose. Once you
have instantiated the second thread, you should have control restored to
your calling thread. Assuming that you are working in windows, as long as
the threads have equal priority (might be worth checking you ahvent given
the child thread too much priority) they should both get a piece of the
processor every so often. You also need to make sure that the calling thread
keeps a reference to the child so that it can kill the thread when your stop
button is pressed.
finally, its worth checking your polling code as that is a common pitfall in
successfully polling for responses. I wonder whether it would perhaps be
better to have a Listener rather than trying to poll so that when the button
is called you will have the listeners method automatically called - you
would probably wrap the listener in a seperate thread (if that is not
automatic?) so that your main application is freed to do other stuff.
actually, if I remember correctly, even if the class that implements the
listener is the same as you main() class, the Listener methods will be
called in a different thread so you may not have any problem with this.
chanoch
-----Original Message-----
From: Cordell Bourne [mailto:cbourne@c...]
Sent: 26 June 2001 01:24
To: Professional Java
Subject: [pro_java] Thread questions
I am just starting to learn about threads and have run into a problem.
I have a UI which starts up which allows a user to set some settings via
checkboxs and list boxes etc. When the user is done, the user can click a
button to start a process. What I am having a problem with in this
scenario is once the process starts its takes over everthing and I would
like to be able to allow the user to click a "Stop" button to stop the
process.
I have read about Threads and somewhat understand what I have read. Here
are my classes
public class UI (this is my main class which starts up my UIFrame)
public class UIFrame (class for all my UI elements and from which the
process starts running)
public class ProcessThread implements Runnable (Class for my process to
run in which calls the main process handling class)
public class Process (Class to do what I need to have done)
The problem I am having is figuring out how to start the process thread
and then poll the event queue to find out when the stop button is pressed.
Any hints or suggestions?