[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Threading opinions

Posted on 2004-11-26
Medium Priority
Last Modified: 2010-03-31
   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!
Question by:petepalmer
  • 2
  • 2
LVL 86

Accepted Solution

CEHJ earned 1000 total points
ID: 12680624
It's usually more flexible to use Runnable:

class DataStorer implements Runnable {
      public void run() {

Author Comment

ID: 12680630
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?
LVL 86

Expert Comment

ID: 12680639
The main difference is that you don't need to subclass Thread itself, so you have greater OO scope

Author Comment

ID: 12680640
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...
LVL 35

Expert Comment

ID: 12680681
> 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


Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month19 days, 3 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question