[727] in java-interest

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

Re: Threads and select ()

daemon@ATHENA.MIT.EDU (Jonathan Payne)
Mon Jul 17 18:06:54 1995

Date: Mon, 17 Jul 1995 12:01:43 -0700
From: jpayne@starwave.com (Jonathan Payne)
To: arista@art.redstar.com
Cc: arista@art.redstar.com, java-interest@java.Eng.Sun.COM,
        arista@art.redstar.com
In-Reply-To: <199507171853.OAA04513@art.redstar.com> (message from Nathan Abramson on Mon, 17 Jul 1995 14:50:53 -0400)

> From: Nathan Abramson <arista@art.redstar.com>
> Date: Mon, 17 Jul 1995 14:50:53 -0400
> X-Sender: arista@192.233.88.1
> Cc: java-interest@java.Eng.Sun.COM, arista@art.redstar.com
> Content-Type: text
> Content-Length: 1370
> 
> At 11:26 AM 7/17/95 -0700, Jonathan Payne wrote:
> >> 
> >> 1) Is the thread multitasking preemptive, or cooperative?
> 
> >Higher priority threads preempt lower priority ones.  Threads at the
> >same priority do not preempt, so that's why yield() is there.
> >
> 
> I hadn't thought of that.  It does make sense (although it is a
> bit annoying).

It doesn't bother me at all.

> >> 2) There is a function to put a thread to sleep for a certain length of
> >>    time.  But is there a way for a thread to sleep while waiting for
> >>    file descriptor activity, ala UNIX select ()?
> 
> >You can block on read(), which implies a separate thread for each
> >socket.  Which may or may not be bad depending one what you're trying
> >to do.
> >
> 
> Would that actually work?  I would think that the first thread to
> execute read() would block and stop all the other threads before they
> could even execute read().

That wouldn't be very multi-threaded of Java, now would it?  It
definitely works.  It's just a question of how many network
connections you think you might have at once, and how you want to deal
with that.  I think using threads works very well most of the time, so
just go for it.

> >I wanted to implement select() a while ago and mentioned it to the
> >java team but they blew me off, so I blew it off.
> 
> It seems to me that select() would best be in the interpreter.
> That way the interpreter could figure out which Threads were waiting
> for what, with what timeouts, and block accordingly.  Otherwise,
> you'd have to make some kind of event loop in your Java program
> with a select() in it, which was what I thought the Java designers were
> trying to eliminate.

I don't really understand what you're talking about here.  It all just
works as you would like, but also, select() might also be nice if you
don't really need or care for each thread doing its own read, keeping
its own state, etc.

-
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