Derek Glidden wrote:
> 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.
Too much task-switching and I/O going on. Take out the println, take out
the yield, and just spin forever:
for (;;);
Run with native threads, of course. Two threads ought to do it.
Terminate with ctrl-C.
Nathan
> [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]