Article View: borland.public.jbuilder.java.language
Article #15577Re: newbie problem with threads
From: Dion Gillard
Date: Sun, 23 May 1999 00:00
Date: Sun, 23 May 1999 00:00
41 lines
2027 bytes
2027 bytes
In article <7htf2m$d0s21@forums.borland.com>, cqcallaw@iname.com says...
| Hi,
| I have a simple multithreaded program that reads in data from a Socket.
| I have a class that extends Thread to handle I/O operations.
| In the run() method of this class I have a loop that reads in that data and
| appends it to a string, then immediately after that I call a method to add
| the string to a Vector. I have verfied that the loop executes, but the
| program seems to stop or slow down dramaticly after the loop finishes.
| Sometimes the string is added to the Vector after a long wait, sometimes it
| doesn't get added at all. What am I doing wrong? Here is my code:
|
| import java.net.*;
| import java.io.*;
|
| class SocketReader extends Thread
| {
| public SocketReader(Socket s)
| {
| socket = s;
| in = new BufferedReader(new InputStreamReader(s.getInputStream()));
| }
| public void run()
| {
| String f = "";
| String m = "";
| while((f = in.readLine()) != null)
| {
| m += f;
| }
| // this is were it sometimes stops
| v.addElement(m);
| }
| Vector v = new Vector();
| Socket socket;
| BufferedReader in;
| }
|
| Any help would be apprectiated.
How about using a StringBuffer rather than a String and using append?
dIon
Technical Details
Message-ID:
<MPG.11b26edca49ec664989686@news.ozemail.com.au>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7htf2m$d0s21@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,57107e8311ab5720 X-Google-Attributes: gidf74b3,public From: dion@multitask.com.au (Dion Gillard) Subject: Re: newbie problem with threads Date: 1999/05/23 Message-ID: <MPG.11b26edca49ec664989686@news.ozemail.com.au> X-Deja-AN: 481116427 Distribution: world References: <7htf2m$d0s21@forums.borland.com> X-Trace: ozemail.com.au 927449484 203.108.100.98 (Sun, 23 May 1999 18:51:24 EST) Organization: Multitask Consulting NNTP-Posting-Date: Sun, 23 May 1999 18:51:24 EST Newsgroups: borland.public.jbuilder.java.language