🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #15637

newbie problem with threads

#15637
From: C. Callaway
Date: Tue, 18 May 1999 00:00
39 lines
1675 bytes
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.

Thanks,
Technical Details
Message-ID: <7htf2m$d0s21@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,57107e8311ab5720,start
X-Google-Attributes: gidf74b3,public
From: "C. Callaway" <cqcallaw@iname.com>
Subject: newbie problem with threads
Date: 1999/05/18
Message-ID: <7htf2m$d0s21@forums.borland.com>
X-Deja-AN: 479373499
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211
Organization: Another Netscape Collabra Server User
X-MSMail-Priority: Normal
Newsgroups: borland.public.jbuilder.java.language