Threading opinions

Hi,
   This is really a follow on from my last question about storing data from a ResultSet. Anyway the processing involved in each set  ( there are three ) is quite intensive and therefore slow. I'd like to write a method for each object that basically runs the various tasks in their own thread. The server has four CPUs so this should really boost performance. I know there are various ways of using threads and was wondering what you guys thought was the best way in this case :)

Thanks in advance!
LVL 1
petepalmerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
It's usually more flexible to use Runnable:

class DataStorer implements Runnable {
      public void run() {
       
      }    
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
petepalmerAuthor Commented:
That's what I thought looking at the tutorial - certainly good to have it confirmed :)

What are the real differences between the two flexibility wise?
0
CEHJCommented:
The main difference is that you don't need to subclass Thread itself, so you have greater OO scope
0
petepalmerAuthor Commented:
I guess as Java only supports inheriting from one class, you'd have no choice but to use Runnable i.e when you write an Applet or something...
0
girionisCommented:
> That's what I thought looking at the tutorial - certainly good to have
> it confirmed :)

> What are the real differences between the two flexibility wise?

It all depends on what you want to do and in you system's design. You mainly implement Runnable if your class needs to subclass (needs to extend) some other class. But there are also differences about how a Runnable or a Thread work.

The Runnable interface only contains one method, the run() method and that's all you need to implement. Your Runnable class *is not* a thread itself but you use the Thread class to run it and therefore you have separate Thread objects all running the same Runnable instance (your Runnable object).

The Thread class on the other hand creates a new Thread object per thread that you want to use.

For a very good explanation between Runnable and Thread have a look here: http://developerlife.com/lessons/threadsintro/default.htm

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.