i've been periodically trying out native threads, hoping to get full
usage from an SMP sytem. so far, no luck. finally abstracted the problem
into a simple, repeatable form.

the following program creates M threads that each make and quit from N
Sockets to an SMTP_HOST.

        java NT SMTP_HOST M N

it always works, for any M, on a uniprocessor, always fails for M>1 on
SMP, sometimes with a shared library load error (!).

only setting THREADS_FLAG=green will stop this behavior.

import java.io.OutputStream;
import java.net.Socket;

public class NT
        implements Runnable
{
        String host;
        int N;

        public NT(String h, int n) {
                host = h;
                N = n;
        }
        public void run() {
                for (int i = 0; i < N; i++)
                        try {
                                Socket sock = new Socket(host, 25);
                                OutputStream out = sock.getOutputStream();
                                out.write("quit\n".getBytes());
                                out.close();
                        }
                        catch (Exception e) { e.printStackTrace(); }
        }
        static public void main(String arg[]) {
                try {
                        String host = arg.length > 0 ? arg[0] : "localhost";
                        int m = arg.length > 1 ? new Integer(arg[1]).intValue() : 10;
                        int n = arg.length > 2 ? new Integer(arg[2]).intValue() : 1;
                        NT soak[] = new NT[m];
                        for (int i = 0; i < m; i++)
                                soak[i] = new NT(host, n);
                        for (int i = 0; i < m; i++)
                                new Thread(soak[i]).start();
                }
                catch (Exception e) { e.printStackTrace(); }
        }
}

> >
> >


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

Reply via email to