🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: newbie problem with threads

#15597
From: Max Polk
Date: Wed, 26 May 1999 00:00
28 lines
1565 bytes
In article <7htf2m$d0s21@forums.borland.com>, cqcallaw@iname.com says...
[HEAVILY EDITED]
> 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:
>     public void run()
>     {
>         String f = "";
>         String m = "";
>         while((f = in.readLine()) != null)
>         {
>             m += f;
>         }
>         // this is were it sometimes stops
>         v.addElement(m);
>     }

You *do* realize that when you start your thread, run gets called (once) 
and when the run method returns, the thread exits.  I don't believe you 
are supposed to start the thread a second time.  Instead, create a new 
one and start the new one.

Alsom, you probably should use StringBuffer, not String.  StringBuffer 
grows but String is immutable.  If the data has any size to it 
whatsoever, you end up really being very inefficient.

Try these two and see what happens.
Technical Details
Message-ID: <MPG.11b670906e6f8bcb9896e3@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <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: none@none.invalid (Max Polk)
Subject: Re: newbie problem with threads
Date: 1999/05/26
Message-ID: <MPG.11b670906e6f8bcb9896e3@forums.borland.com>
X-Deja-AN: 482551994
References: <7htf2m$d0s21@forums.borland.com>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.language