Received: from SOUTH-STATION-ANNEX.MIT.EDU by po7.MIT.EDU (5.61/4.7) id AA24076; Fri, 15 Mar 96 09:41:01 EST
Received: from liquor.cabi.net by MIT.EDU with SMTP
	id AA15426; Fri, 15 Mar 96 09:40:12 EST
Received: by liquor.cabi.net (8.7.3/8.7.3) id JAA08757; Fri, 15 Mar 1996 09:39:27 -0500
Resent-Date: Fri, 15 Mar 1996 09:39:27 -0500
Date: Fri, 15 Mar 1996 15:37:40 +0100
From: Lincoln Stein <lstein@kaa.crbm.cnrs-mop.fr>
Message-Id: <199603151437.PAA06152@pico.crbm.cnrs-mop.fr>
To: java-linux@java.blackdown.org
Subject: Thread.yield() doesn't
Cc: mieg@kaa.crbm.cnrs-mop.fr
Resent-Message-Id: <"_CB823.0.s72.s3OIn"@liquor>
Resent-From: java-linux@java.blackdown.org
X-Mailing-List: <java-linux@java.blackdown.org> archive/latest/1399
X-Loop: java-linux@java.blackdown.org
Precedence: list
Resent-Sender: java-linux-request@java.blackdown.org

Hi all,

Here's another question that's more Java-oriented than Linux oriented,
but you've been so helpful with my previous problems that I thought
I'd try again.

My program opens up connections to a database via a TCP/IP connection,
retrieves some information and displays it.  The database is a large
object-oriented db of genomic information and contains both large
objects, such as DNA sequences, and small objects such as author's
e-mail addresses.

Since the database itself is multi-threaded, I take advantage of that
fact by spawning a new thread every time a database access is needed,
opening up a new database connection (or reusing an old inactive one),
and downloading and parsing the information as a background task.

The problem is that time-slicing doesn't seem to be implemented on the
Linux platform.  The first thread grabs the CPU and holds onto it
until its inner read-and-parse loop is done.  Very annoying.

So I RTFMed and found the Thread.yield() call.  I threw that into the
inner loop and no dice: thread swapping is still not working.

So I changed the Thread.yield() call to Thread.sleep(10), and that
works just fine.  The threads download and parse in parallel.
Unfortunately there's now a 10 msec wait in my inner loop, so
everything crawls, but I think this test excludes the possibility that
my synchronized methods are holding locks and not relinquishing them.

I've played with setting priorities, but this doesn't seem to improve
things.  Does anyone have an idea of what might be going wrong?  Are
there subtleties to the yield() method that I don't understand?

Lincoln

