[2674] in java-interest

home help back first fref pref prev next nref lref last post

Thread stop

daemon@ATHENA.MIT.EDU (roger day)
Tue Oct 10 08:53:20 1995

Date: Tue, 10 Oct 1995 11:58:01 +0100
From: roger day <roger@ssynth.co.uk>
To: java-interest@java.sun.com

I'm coding in the pre-beta JDK on Solaris 2.4.
I'm using the api to "mimic" rpc calls as follows in the fragment of
code.
// this is the bit that stops the thread  running
	public void close_connection () {
		System.out.println("Stop!");	
		stop();
	}
// This is the code that the runs in the thread 
public void run () {
		byte	b[] = new byte [100];
		int     nbytes;
		Integer ModuleID, id;
		int	slength;
		String	response;
		while (true) {
	        	try {
			        nbytes = in.read(b,0,4);	// Read the input
				response = new String(b,0,0,nbytes);		
				System.out.println("nbytes= "+nbytes);
				System.out.println("response= "+response);
				ModuleID = new Integer(response);
				System.out.println("ModuleID = " + ModuleID);

	        		switch (ModuleID.intValue()) {
					case 1000:
						close_connection();
						break;
					case 1001:
						stuff1();
						break;
					case 1002:
						stuff2();
						break;
					default:
						System.out.println("No such method");								
				}				
        		} catch(Exception e) {
         	  	     System.out.println("exception in run " +
e.getMessage());
          	 	     return;
        		}
		}
	}

The only problem occurs when I make a call to "close_connection", with
stop.

As far as I can tell, the thread is happy, but the stop call throws up
the following exception:

"exception in run String index out of range: -1"

which really confuses me. Is there something deeper going on? Or is it
just a minor glitch?

Cheers,

Roger.

-- 
==============================================================================
		"Pugh, Pugh, Barney McGrew, Cuthbert, Dibble, Grubb"
		http://www.ssynth.co.uk/ssl/roger.html or
		http://www.ssynth.co.uk/~rday/poet_mag.html
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post