On Wed, 3 Jul 2002, Alex Loubyansky wrote:
> The thing that haven't changed in 2.0.5.
> When the framework is undeployed cleaning threads keep on running.
We use WeakRef's for that pattern.
Starting from:
class Cleaned {
...
new Thread() { ...
while(true) {
... implicitely use outer this here ...
Thread.sleep();
}
}
}
we refactor to something like:
class Cleaned {
static class Cleaner extends Thread {
Cleaner(Cleaned outerThis) { this.ref = new WeakRef(outerThis); }
public void run() {
while(true) {
Cleaned outerThis = (Cleaned)ref.get();
if(outerThis == null) break; // terminate cleaner
... use cleaned ...
outerThis = null; <-- ****
Thread.sleep();
}
}
}
new Cleaner(this).start();
}
The **** is a little tricky here. The VM does some kind of local analysis
anyway and I'm not sure whether this will always work/is necessary to get
rid of the reference to the outer.
The nice thing about this is that it's a very local solution. No need to
register with anyone.
Cheers
Matthias
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
No, I will not fix your computer.
http://thinkgeek.com/sf
_______________________________________________
Tapestry-developer mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/tapestry-developer