Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Advanced-java] enclosing class creating a thread advice


  • From: dave.wathen@xxxxxxxxxxxx (Dave Wathen)
  • Subject: [Advanced-java] enclosing class creating a thread advice
  • Date: Thu, 14 Mar 2002 18:04:44 -0000

In what way is this solution different to using Runnable?

Dave Wathen
Canzonet Limited
http://www.canzonet.com
mailto:dave.wathen@xxxxxxxxxxxx

-----Original Message-----
From: advanced-java-admin@xxxxxxxxxxxxxxxxxxxxxx
[mailto:advanced-java-admin@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Nikolaos
Giannopoulos
Sent: 14 March 2002 13:54
To: Tim O'Neil; advanced-java@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [Advanced-java] enclosing class creating a thread advice




> From: advanced-java-admin@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:advanced-java-admin@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Tim
> O'Neil
>
> I have a class that spins off a thread to do some work on a
> data file. This class hangs subordinate classes out to do
> i/o and random access file work that must be referenced by
> the thread. I am currently passing a reference to the entire
> enclosing class to the thread so it has all the stuff it needs
> to do its thing. This works, but it seems kinda ugly to me.
> I wonder if this is the way to go or does this seem like a
> scenario for reflection or some other method?


If you are passing in a specific class then this probably seems ugly because
the solution doesn't seem flexible enough.  How about doing the following:

public interface ThreadWork {
  public void doWork();
}

public class SomeThreadWorkA implements ThreadWork {
  public SomeThreadWorkA() {}
  public void doWork() {
    // Actual Work specific to this class A
  }
}

Now your ThreadWorker can hold references to ThreadWork objects and simply
invoke doWork() on without really caring what the actual work does - since
it is specific to the work itself (and encapsulated therein) and not part of
the interface.

HTH.

--Nikolaos


_______________________________________________
Advanced-java mailing list
Advanced-java@xxxxxxxxxxxxxxxxxxxxxx
http://lists.xcf.berkeley.edu/mailman/listinfo/advanced-java