File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Creating / Running / Interrupting my thread Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Creating / Running / Interrupting my thread" Watch "Creating / Running / Interrupting my thread" New topic
Author

Creating / Running / Interrupting my thread

Sam Bluesman
Ranch Hand

Joined: Nov 21, 2004
Posts: 188
Hi there.

I have a program consisting of 4 classes at the moment:

MainProgram.java class
FileProcessor.java class
FileCreator.java class
ServerCommands.java class

The MainProgram class provides an interface where somebody can input a file name and press a button 'Go'. This file name is then passed to the FileProcessor.

The FileProcessor class interprets the data in the user input file and passes some of the interpreted data to the FileCreator class, which stores this data in a new file.

Having done this, the ServerCommands class is then invoked, which issues commands that uses the file to a statistical server that interprets these and produces a statistial output. However, as this takes some time to do and plots the data in a new window that needs to ineractive while open, I want to run the ServerCommands class as a thread, so that the GUI created by the MainProgram class is still accessible and functional whilst this is going on.

On the MainProgram GUI I have a button 'Reset'. What I would like to know is how I can stop the thread from this MainProgram class.

I am new to threads and have read the API, Java tutorial AND chapter 8 of 'Learning Java' by Niemeyer & Knudsen but I am still having difficulties achiveing the desired effect. Could anyone help me?

So far, to invoke the FileProcessor class from the MainProgram, having clicked the Go button, the following code was used:


So, after control has been passed to the FileProcessor class, it processes the file and hands over to the FileCreator class, which writes to a file. Once the file has been created, control should hand over to the ServerCommands class. Here is the bottom of the FileCreator class which is invoked from the ProcessFile class:

The ServerCommands looks like the following:


Here is the code so far for the event for when the Reset button is activated. This is in the MainProgram class, and it is this that I want to use to Interrupt the thread in the ServerCommands class:



Thanks

Sam

[ July 09, 2007: Message edited by: Sam Bluesman ]

[ July 09, 2007: Message edited by: Sam Bluesman ]

[ July 09, 2007: Message edited by: Sam Bluesman ]
[ July 09, 2007: Message edited by: Sam Bluesman ]

Moosey knows best
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating / Running / Interrupting my thread
 
Similar Threads
Threads and Classes?
new to linux
Dan's Question
Desktop problem
Problems interrupting a thread