Counting the Threads be enumerating through them is a little bit of a
cludge, but doing trying to keep a threadcount seperate from the jvm is
worse. At least the changes only effect one part of the code if I do it
like below.

And a bunch of the threads (like the connectionhandlers) are not specific
to the client, which complicates things because the node has thread
handeling and shit.

On Mon, Aug 21, 2000 at 11:31:05AM +0100, Ian Clarke wrote:
> 
> What about having each thread point to an object containing an
> integer.  When each thread starts the integer is incremented (starting
> at 0), and when each thread terminates the integer is decremented.  If
> the last thread finds that the integer is 0, then it calls
> System.exit() with a return value that was previously set.
> 
> Ian.
> 
> > Unfortunately this seems harder said then done in java. If somebody knows
> > a good way to do it I would be very interested.
> > 
> > (Note: I am well aware of the System.exit(int) method, but the clients are
> > multithreaded, so I don't want to finish "now" I want something like
> > System.setExitStat(int) so that it returns that exit status when it exits
> > normally because all the threads have ended. Otherise I'll have to do
> > something like:
> > 
> >     Thread[] ts; int count;
> >     do {
> >         CurrentThread.yield();
> >         count = 0;
> >         ts = new Thread[Thread.activeCount()];
> >         int n = Thread.enumerate(ts);
> >         for (int i = 0; i < n ; i++) {
> >             if (!ts[i].isDaemon())
> >                 count++;
> >         }
> >     } while (count > 1);
> >     System.getRuntime().exit(exitStatus);
> > 
> > which is a little kludgy).
> > 
> > 
> > > Mark Roberts
> > > mroberts100 at mediaone.net
> > > 
> > > _______________________________________________
> > > Freenet-dev mailing list
> > > Freenet-dev at lists.sourceforge.net
> > > http://lists.sourceforge.net/mailman/listinfo/freenet-dev
> > > 
> > 
> > -- 
> > \oskar
> > 
> > _______________________________________________
> > Freenet-dev mailing list
> > Freenet-dev at lists.sourceforge.net
> > http://lists.sourceforge.net/mailman/listinfo/freenet-dev



-- 
\oskar

_______________________________________________
Freenet-dev mailing list
Freenet-dev at lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/freenet-dev

Reply via email to