Re: Safety of running and stopping dynamically loaded code


Peter Seibel (peter@javamonkey.com)
19 Mar 1999 17:26:32 -0800


>>>>> "Doug" == Doug Lea <dl@cs.oswego.edu> writes: >> synchronized(java.lang.Math.class) { >> absolutelypositivelymustcomplete { for (;;) { try { >> Thread.sleep(1000); } catch (Throwable t) {} } } } >> >> // for absolutelypositivelymustcomplete, substitute David's >> catch/respawn // code, or its moral equivalent >> >> Now, just synchronizing on a class object by itself isn't >> necessarily fatal. I can synchronize on, say, >> java.lang.VerifyError.class all day long, and the only person >> who'd notice is someone else who's as silly as I am. >> Math.class is different, because Math has a static synchronized >> method. By holding the lock, I prevent anyone else from >> computing random numbers. Doug> Well, the funny thing about this particular example is that Doug> I can see no reason that Math.random() needs to be Doug> class-lock synchronized. The underlying java.util.Random Doug> object internally synchs anyway. Even the lazy creation in Doug> Math.random is OK without synch, although it takes a subtle Doug> argument to show this is so. Doug> In any case, the fact that any code can externally grab the Doug> lock for any object (including class objects) is clearly a Doug> design flaw in Java. Lack of programmer-specified protection Doug> against external locking is inconsistent with every other Doug> construct in the language. Well, you could just pretend that synchronized methods don't exist; instead of: class X { synchronized void foo() {} } do: class X { private Object lock = new Object(); void foo() { synchronized(lock) {} } } No? -Peter -- Peter Seibel Perl/Java/English Hacker peter@javamonkey.com There's no good culture without a dash of bad taste; a monopoly of good taste suggests restraint -- you're not pushing the envelope. -- Jean-Louis Gassee ---------------------------------------------------------------------------- To unsubscribe (or other requests) mailto:majordomo@media.mit.edu List archives, FAQ, member list, etc. http://gee.cs.oswego.edu/dl/javares/



This archive was generated by hypermail 2.0b3 on Sat Mar 20 1999 - 07:38:50 EST