[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference abbott::java

Title:JAVA
Moderator:KOALA::CIOT
Created:Mon Nov 13 1995
Last Modified:Wed Jun 04 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:236
Total number of notes:1251

214.0. "JVM Deficiencies" by DECWET::PERRY () Wed Feb 26 1997 19:59

	While using Java on Digital Unix, my co-workers and I discovered a few
problems with the JVM which, if they persist into the official releases will
make it virtually impossible to develop a viable product.

1) The threading mechanism is non-preemptive.

2) The java debugger informs us that:
    *** WARNING - jdb does not yet work on this platform ***

There is also a question of the robustness of the VM. Our product will be rather
stressful on the virtual machine. For example, Jigsaw is an http server written
in Java. This URL:
	http://www.w3.org/pub/WWW/Jigsaw/User/Introduction/performance.html

discusses issues relating to the performance of their application. There is a
discussion under Java implementation problems which talks about the problems
they had with the VM.

	We are depending upon Java 1.1, since we are heavily dependent on RMI,
preemptive scheduling of threads, and a virtual machine that can deal with large
working sets. Therefore we would like to get some idea about if these things are
being addressed or even thought about. We are willing to discuss this offline if
this is not the appropriate place to discuss such things.

Thank you.

-Reggie
T.RTitleUserPersonal
Name
DateLines
214.1Better things on the horizon?NETRIX::"[email protected]"John McNultyThu Feb 27 1997 05:0712
The project team  putting out our JDK is headed by someone called
Will Kling.  Try approaching him with this. Bill Mckeeman is another
name to try if you can't get hold of Will.

I also believe that we're due to ship our own JIT for Digital UNIX
somewhere in the March time frame.  Maybe this implementation will
address the points you've raised. 

Best of luck ..

John
[Posted by WWW Notes gateway]
214.2TLE::JRICHARDThu Feb 27 1997 09:3115
> 1) The threading mechanism is non-preemptive.

IMHO, this is among the worst problems with most JVMs wrt servers.  
My workaround is to just stick a sleep() into every thread's loop.

I understand that this problem stems from the fact that most
Unix implementations don't have reentrent semaphores (something
that Java depends upon) so Sun decided to use "Green threads"
instead of the native threads implementation.

More fallout from this is that java threads only run on one
processor per JVM.

It may be that our java port will use native threads?

214.3Poor-man's timeslicing?HOUBA::MEHERSDamian, http://bigbird.geo.dec.com/Thu Feb 27 1997 11:1921
    
    sleep() or maybe yield()
    
    The OSF's JDK port does pre-emption - has the Digital version
    regressed? (I don't have DUNIX 4.0, so can't check).
    
    My understanding is that *all* implementations are pre-emptive, but some
    are not time-sliced (ie a high priority thread will always pre-empt a lower
    priority thread, but two threads with the same priority will not
    necessarily time-slice).  Nit picking I know, but the difference is
    important.
    
    Not very satisfactory, but did you consider the poor man's
    time-slicing, having a high priority thread that does nothing but
    wake up every second or so, thus giving the VM a chance to schedule
    another thread?
    
    
    	/Damian
    
    
214.4TLE::JRICHARDThu Feb 27 1997 11:2311
>    sleep() or maybe yield()

I haven't researched this to be sure, but I understand that
yield() doesn't /have/ to give up control if the scheduler decides
in the yield() call that it doesn't need to (no higher priority
threads ready).


Actually, I'm a little annoyed at Sun for not rigorously defining
the thread scheduling model.  Hopefully that will come later.

214.5HOUBA::MEHERSDamian, http://bigbird.geo.dec.com/Thu Feb 27 1997 11:3338
    
    JDK 1.1 indicates that a thread will yield to another runnable
    thread when it calls yield() - so it *should* work.
    
    FWIW, could someone with DUNIX 4.0 and the Digital version of the JDK
    try the following out?  The higher priority thread should pre-empt the
    lower priority thread.  If it doesn't then I sincerely hope things get
    better with the JDK 1.1 port.
    
    import java.io.*;
    
    class test {
        public static void main(String[] args) {
          Thread low = new Thread(new LowThread());
          Thread high = new Thread(new HighThread());
    
          high.setPriority(Thread.NORM_PRIORITY + 1);
          high.start();
          low.start();
        }
    }
    
    class LowThread implements Runnable {
        public void run() {
          System.out.println("Low Started");
          for(int i = 0; i < 100000000; i++);
          System.out.println("Low finished");
        }
    }
    class HighThread implements Runnable {
        public void run() {
          System.out.println("High started, going to sleep");
          try {
              Thread.currentThread().sleep(1000);
          } catch(Exception e) {}
          System.out.println("High is Awake, and finishing");
        }
    }
214.6schedulingTLE::JRICHARDThu Feb 27 1997 13:2439
Is there a good reference for thread scheduling under java?

I used Digital UNIX port a couple times, it did support preemption, 
but not timeslicing.


The only documetation I could find about yield is:

  public static void yield()

     Causes the currently executing thread object to temporarily pause 
     and allow other threads to execute. 


So, an arbitrary JVM wouldn't have to reschedule the threads if
the rest of the threads were running at a lower priority (possibly
the same priority too).  I'm guessing this because I assume the 
"other threads" might only mean higher priority threads.  It isn't
very clear.

I've found that:

yield() in the higher priority thread doesn't let the lower
priority thread run

yield() in the low priority thread allows the higher one to run
(as expected)

yield() does in fact work round-robin for same priority threads
(at least in the OSF1 and linux case)

if the low thread starts just before the high thread, the high thread
runs (I could guess why, but I'd probably be wrong)

if the low thread starts a few seconds before the high thread, the low
thread runs until the scheduler is called again (as you might expect)


There's probably more...
214.7more infoTLE::JRICHARDThu Feb 27 1997 20:0919
I poked around in Doug Lea's "Concurrent Programming in Java"
tonight; here's what I found:

(p24) The Thread.yield method relinquishes control, which may enable one 
or more other threads of equal priority to run.

(p211) [lists "sleep" and the "high priority thread shakes up the
scheduler" methods of forcing preemption.  Also says:
the Java Language Specification does not guarantee that threads 
tied for the highest priority are run fairly.

It also mentions something I missed before: 

  One of the runnable threads with the highest priority
  is alwasy chosen to run.

And they give some techniques to ensure fair secheduling.

214.8HOUBA::MEHERSDamian, http://bigbird.geo.dec.com/Fri Feb 28 1997 03:204
    JDK 1.1 says yield() "Causes the currently executing Thread object to
    yield. If there are other runnable Threads they will be scheduled next. "
    
    	/Damian
214.9hmm...TLE::JRICHARDFri Feb 28 1997 08:3310
When I just checked the 1.1 docs at
http://www.javasoft.com:80/products/jdk/1.1/docs/api/java.lang.Thread.html#yield
()
had what I first posted...

Interestingly, the sleep docs don't mention scheduling either.

I'm probably reading too much into this.  After all, Java is still
developing, I'm sure the docs will get sorted out to something
sane eventually.
214.10jammer.zko.dec.com::JackMarty JackFri Feb 28 1997 08:562
If it helps, we expect the JDK 1.1 release to use
native threads.
214.11Re. -1: It might helpDECWET::PERRYFri Feb 28 1997 15:515
It will help that JDK 1.1 uses native threads only if the rest of the VM can
take a good pounding. I would say that one way you could test your
implementation is by compiling Jigsaw, running it on a multiprocessor machine
and doing bunches of HTTP requests. If the VM falls over, then you know you
still have some work to do. Note that this is only a first level test.