Re: java cocoa appkit application and multiple threads
Re: java cocoa appkit application and multiple threads
- Subject: Re: java cocoa appkit application and multiple threads
- From: Michael Dupuis <email@hidden>
- Date: Thu, 24 May 2001 14:41:09 -0400
>
> threads that all have access to the same window. This allows me to keep
>
> the
>
> UI responsive, display the progress indicator, etc.
>
>
do you mean that your extra thread has access to the progress indicator
>
object, and you simply call its update methods from that extra thread?
Yup, that's exactly what I meant. For instance, I use the thread to retrieve
data from a database. As it's retrieving the data, I am updating the
progress indicator.
you could however, just set start the progress indicator animation as well.
Once you spawn the new thread, the UI animation is allowed to run. Before I
did this, everything was paused waiting for my process to continue.
>
>
> When my thread completes, it calls back to the window that spawned it and
>
> sets any data that was being generated. It all seems to work pretty well.
>
>
what do you mean by "calls back"? do you simply call the necessary update
>
methods from the extra thread?
Yeah, by calls back, I meant uses a reference to the window that spawned it
to call a method to set the data that was returned.
One thing of not that I think I forgot to mention. In your threads, the code
in the run() method must be written like this:
int poolCounter = NSAutoreleasePool.push();
// Do what you want to do
NSAutoreleasePool.pop(poolCounter);
If isn't done, you'll get messages telling you that you are 'leaking'
objects.
>
>
in my case, i have an NSTableView the data of which needs to be obtained by
>
the extra thread. i also have a progress bar. do i simply call the necessary
>
progress bar update methods in the extra thread while the data is being
>
loaded? Once the data is all loaded, do i then call NSTableView.reloadData()
>
from the extra thread to get it to display the new data?
Pretty much, that's what I am doing, in a nutshell, and I haven't had any
problems.
Hope that helps...
Michael