Date: Wed, 13 Jan 1999 09:50:54 -0700 From: Nate Williams <nate@mt.sri.com> To: Justin Wells <reader@semiotek.com> Cc: freebsd-java@FreeBSD.ORG Subject: Re: busywait in IOstream code? Message-ID: <199901131650.JAA27754@mt.sri.com> In-Reply-To: <19990112212038.E2400@semiotek.com> References: <19990112212038.E2400@semiotek.com>
next in thread | previous in thread | raw e-mail | index | archive | help
> I have a multithreaded program which normally runs under a web server, > but I have a bunch of command line test harnesses that I run against it, > basically I type in a command and it does something--I use this to debug > my program. > > However, I noticed when doing this that my background threads weren't > ever getting a chance to execute. Doing this in a high priority thread: > > for(;;;) { sleep(someTime); } > > solved the problem (causes a thread scheduling event every someTime msecs). > > I conclude from this that there is some code in IOStream that is > busywaiting and not yielding. All system calls (which involves all I/O) in FreeBSD blocks until it finishes by the very nature of a single-threaded kernel. This is not a JVM problem, but a problem with *ALL* Java implementation which use green-threads, which attempt to emulate kernel threads. By throwing in your high priority thread doing the sleep, it makes the green threads solution a bit more deterministic by kicking the scheduler which attempts to (badly, but better than nothing) allow other threads to be scheduled. In Java on unix, threads are not pre-emptively scheduled, but each thread is allowed to run till whenever it decides to give up (not quite true, but for the most part true). This is the same behavior as on the Solaris 'reference' platform and is not specific to FreeBSD. It's not an issue of busy-waiting, it's an issue of not using pre-emptive multi-tasking (which is not a requirement). For a better description of the above behavior, see the O'Reilly book 'Java Threads' by Oaks et al. Nate To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-java" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199901131650.JAA27754>