Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Cancel Function for Ongoing Process Question
I have an application that downloads a series of items from a web site -
with J2SE.  I want to implement a cancel function.   I'm gathering this
means I need to use threads in order to interupt the download - is this
correct or am I complicating this?

One approach I've used with other languages - like VB6 - is to poll the
GUI - but I gather thats not very good practice in Object Oriented,
Event driven applications.   I also can't figure out how to poll a
button for its state anyways - is this possible?

If threads are the correct approach - is there a simple pattern or
example that explains how to do this - without getting into J2EE or
client - server complications - (beyond my expertise at this point)?

Thanks !

- Ben Hoffmann


Report this thread to moderator Post Follow-up to this message
Old Post
Ben Hoffmann
09-21-04 09:02 AM


Re: Cancel Function for Ongoing Process Question
Ben Hoffmann wrote:
> I have an application that downloads a series of items from a web site -
> with J2SE.  I want to implement a cancel function.   I'm gathering this
> means I need to use threads in order to interupt the download - is this
> correct or am I complicating this?

In theory, there are two possibilities here: use multiple threads, or
use asynchronous (non-blocking) I/O functions.  However, because you are
using a graphical user interface, you are required to perform blocking
operations outside of the event dispatch thread.  That means that
although you still have the choice of blocking or non-blocking I/O, you
will need to create a new thread in either case.

> If threads are the correct approach - is there a simple pattern or
> example that explains how to do this - without getting into J2EE or
> client - server complications - (beyond my expertise at this point)?

The basic idea behind it is as follows:

// in some accessible location:

Thread t;

// in an event handler:

t = new Thread(new Runnable() {
public void run()
{
try
{
// code to read from socket
}
catch (InterruptedIOException e) { }
catch (IOException e)
{
handleException(e);
}
}
});

t.start();

And later, to cancel:

t.interrupt();

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Report this thread to moderator Post Follow-up to this message
Old Post
Chris Smith
09-21-04 09:02 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:20 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.