Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Norm

Thread: Threading in Java

  1. #1
    kfcnhl is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default Threading in Java

    I have implemented threading using inheritance of Thread class and runnable class.
    Currently I have four cores in my CPU, but only one seems to be busy even if I open up 10+ threads.
    Although the speed is much faster.

    Does anybody know why?

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: Threading in Java

    You've provided little information. For instance, we don't know how you are creating and starting the threads.

    using inheritance of Thread class and runnable class.
    Runnable is an interface, not a class. Again no information, but based upon the above sentence my .02: do not use inheritance - implement Runnable and pass this to a Thread object.

  3. #3
    kfcnhl is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default Re: Threading in Java

    I just love how people pick up the insignificant details. Typical computer scientist.

    My class implements runnable so it have run() method.
    I then create thread using the runnable interface.

    I have seen that IO can be an issue.
    But I am only outputing with system.out.println.

    Not sure if that have any effect.
    Let me know if there are any other potential factors, otherwise my code looks similar the below.

    class BasicThread2 implements Runnable {
    // This method is called when the thread runs
    public void run() {
    }
    }

    // Create the object with the run() method
    Runnable runnable = new BasicThread2();

    // Create the thread supplying it with the runnable object
    Thread thread = new Thread(runnable);

    // Start the thread
    thread.start();

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: Threading in Java

    Quote Originally Posted by kfcni
    I just love how people pick up the insignificant details. Typical computer scientist.
    And I just love how people disregard advice as insignificant...means that's one less post I will spend my time answering.

  5. #5
    kfcnhl is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default Re: Threading in Java

    Somebody on another forum just relied that XP, the OS I am using, does not allocate more than one CPU for a process.

    That is stupid.............
    Any workaround?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

Similar Threads

  1. Java Mem and threading tips
    By masijade in forum Reviews / Advertising
    Replies: 2
    Last Post: 06-16-2011, 04:30 PM
  2. Getting problem in threading in JAVA
    By Chetans in forum Threads and Synchronization
    Replies: 3
    Last Post: 03-19-2010, 07:49 AM
  3. Java threading
    By Eranga in forum Advanced Java
    Replies: 2
    Last Post: 03-13-2008, 05:30 AM
  4. question about Multi threading in Java
    By fred in forum Advanced Java
    Replies: 1
    Last Post: 07-24-2007, 01:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •