do we need separate thread for FirstThread
Cedric Berger
cedric@wireless-networks.com
Thu Feb 8 17:12:00 GMT 2001
Per Bothner wrote:
>> Cedric Berger <cedric@wireless-networks.com> writes:
>> > Per Bothner wrote:
> > >
> > > Bryce McKinlay <bryce@albatross.co.nz> writes:
> > >
> > > > > * Avoid creating threads in single-threaded programs.
> > > >
> > > > Well, we can't really do this, since a separate finalization thread (for
> > > > example) will be required in order to implement finalization correctly.
> > >
> > > I'm missing something here. The JLS says finalizer are run in an
> > > "unspecified" thread. There seem to be two logical alternatives:
> > > (1) a special finalizer or gc thread, or
> > > (2) the thread that causes gc to be invoked (by doing a new).
> > > Why is (2) prohibited?
> >
> > (2) is prohibited in a multithreaded application because of risks
> > of deadlock.
>> Could you explain why?
> [...]
> I guess I could conceive of a finalizer
> waiting for a resource being held by the thread doing the 'new',
That's it.
> Is there any non-bogus program that could benefit from this?
I've no supernatural powers to tell you that.
Probably no 'pure-java' programs, where finalizers are a bad
idea anyway. But I can think of a control program I wrote once
(involving lots of native code, running 24h/24) where a
finalization appening at the wrong time during a new could have
caused a deadlock. Of course, this would probably append only
once in (1..10) years I would guess.
> And is there anything in the specs
> (or otherwise) that prohibits (2)?
I don't know.
Cedric
More information about the Java
mailing list