O'Reilly logo

Java RMI by William Grosso

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Basic Terminology

To understand threads, we need to step back for a moment and recall some basic ideas from computer science. In particular, we need to talk for a moment about the stack and the heap.

Tip

Readers who feel comfortable with the basic concepts that underly threading might want to jump ahead to Section 11.2.5.

The Calling Stack

A stack is a data structure that serves as a container. You can insert and remove items from a stack. The only restriction is that the only item that can be removed is the item that was most recently inserted. Stacks are often visualized as a pile of items. You insert items[62] by placing them on the top of the stack; you can remove only the item on top of the pile. See Figure 11-2.

The calling stack

Figure 11-2. The calling stack

While running, a program maintains a calling stack of methods that it is currently “in.” Consider the following code:

private class GetBalanceAction implements ActionListener {
	public void actionPerformed(ActionEvent event) {
		try {
			getAccount(  );
			resetBalanceField(  );
			releaseAccount(  );
		}
	.....
	}
}

When actionPerformed( ) is called, the top element of the stack corresponds to the actionPerformed( ) method. When getAccount( ) is called, information corresponding to getAccount( ) is placed on top of the calling stack. When getAccount( ) returns, the stack frame corresponding to getAccount( ) is removed from the calling stack, and the information ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required