C
Chris Cornell
Hello,
I have a question regarding threads or runnable's in Java. I
implemented a class Foo() that implements Runnable that basically has
a method called sync() that when called loads a URL and reads the data
from it and stores it in a Hashtable that is also a private member of
the class. The class' run() method simply calls sync() once and
that's it. There are other methods that are present that extract the
data from the Hashtable and returns it.
My question is, certain external events (maybe a user event) triggers
the need to call sync() again to re-synchronize the data in the
Hashtable with the authoritative data from the webpage. Is this call
asynchronous? Meaning, am I implementing it just the same as having
my class Foo as a regular class? I'm instantiating Foo in my main
application like:
Foo f = new Foo();
new Thread(f).start();
The reason why i wanted to create Foo as a thread is so that I can
periodically just tell it re-synchronize in the background while my
busy application can keep working. If my implementation is poor, can
anyone suggest a better approach to synchronize data without blocking
the entire main execution thread? I understand that
thread-synchronization is necessary while my Foo object is
synchronizing and I can take care of that.
Thanks in advance,
Chris
I have a question regarding threads or runnable's in Java. I
implemented a class Foo() that implements Runnable that basically has
a method called sync() that when called loads a URL and reads the data
from it and stores it in a Hashtable that is also a private member of
the class. The class' run() method simply calls sync() once and
that's it. There are other methods that are present that extract the
data from the Hashtable and returns it.
My question is, certain external events (maybe a user event) triggers
the need to call sync() again to re-synchronize the data in the
Hashtable with the authoritative data from the webpage. Is this call
asynchronous? Meaning, am I implementing it just the same as having
my class Foo as a regular class? I'm instantiating Foo in my main
application like:
Foo f = new Foo();
new Thread(f).start();
The reason why i wanted to create Foo as a thread is so that I can
periodically just tell it re-synchronize in the background while my
busy application can keep working. If my implementation is poor, can
anyone suggest a better approach to synchronize data without blocking
the entire main execution thread? I understand that
thread-synchronization is necessary while my Foo object is
synchronizing and I can take care of that.
Thanks in advance,
Chris