Nathan Meyers wrote:
> 
> OK... so one other question you haven't answered. Are you sure you've
> got two threads staying busy? Most of Java's threads spend most of their
> time sitting around and waiting. If you've really got two threads
> spinning and you're not seeing 100% load, something's strange -- and
> it's not a command-line switch.

I don't know for sure since, as I said, I haven't done a lot of
multi-threaded programming. I've run a few third-party Java apps, but
have no idea on the whole how thread-intensive any of them are.   

These two classes are a couple of stupid little things I wrote to see if
I understood Java's threading and this is what I've been primarily
running to see if I can get the JDK to use more than one CPU
simultaneously.

[threadone.java:]

import java.io.*;
import java.lang.*;

public class threadone extends Thread {

    String msg = null;

    threadone(String message) {
        super();
        msg = message;
    }

    public void run() {
        for(int x = 0; x < 100; x++) {
            System.out.println(msg);
            yield();
        }
    }
}

[mythreads.java:]

import java.io.*;
import java.lang.*;

public class mythreads {
    public static void main(String args[]) {

        int numthreads = 100;

        for (int i = 0; i < numthreads; i++) {
            threadone t = new threadone("This is thread " + i);
            t.start();
        }
    }
}

Assuming this does what I think it should do - start a bunch of threads
all concurrently printing a silly message to the console (unless they're
blocking each other at some level because of the console output, which
is entirely possible) - this app will only hit 50% usage on my SMP
system using native_threads. 

But, like I said, running *any* Java app with native_threads set on my
SMP box only ever results in 50% usage.  I find it awfully hard to
believe that I have not yet encountered a truly multithreaded Java app
that can fully take advantage of more than one CPU - and this is true of
both 1.1.7v3 and 1.2-pre2 on this box.

I've not been using a JIT in any of these cases to try to limit the
possible variables.

Thanks for taking the time to help out and also confirming that, as I
thought, this is (as they say) passing strange behaviour.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
With Microsoft products, failure is not           Derek Glidden
an option - it's a standard component.      http://3dlinux.org/
Choose your life.  Choose your            http://www.tbcpc.org/
future.  Choose Linux.              http://www.illusionary.com/


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to