wrapper object of "me" as a field in me

Interesting thread pattern.

Usually the wrapper object is a different class containing a field holding the wrapped object, but In this example, …. see comment below. What’s the motivation? In a thread pool, I think this is how a task (implementing Runnable.java) from the queue is assigned a thread from the pool.

In memory, the thr object and THIS object hold pointers to each other. “wrapper” is misleading term. wrapper is a one-way HAS-A relationship.

In an object graph (at GC time), you often find 2 objects connected both ways, but in this case the 2-way linking is extremely barebones. Tight-coupling?

class MyThr implements Runnable{
Thread thr; // ----> a field but also a wrapper of this object
MyThr(){
this.thr = new Thread(this);
this.thr.start();
}
...
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s