Java Reference
In-Depth Information
FIGURE 12-47
Figure 12-48 displays lines 681 through 691 of the WebStocks servlet code.
The getStockList() method returns an ArrayList containing the stock holdings
for a given userID (line 681). Because the data access class, StockTrackerDB,
contains a method that also returns an ArrayList of stock holdings from the
database for a given userID, it is called within a synchronized block of code.
Although this method only accesses and does not update the database, by
placing the call within a block of code synchronized on the StockTrackerDB
object, the stock holdings of the user cannot be changed by another thread
during this access, as long as the other thread also uses synchronized access to
the StockTrackerDB methods.
FIGURE 12-48
Figure 12-49 displays lines 692 through 703 of the WebStocks servlet
code. Like the previous method, this method also obtains an ArrayList from
a StockTrackerDB method within a synchronized block of code (line 699).
Instead of returning the ArrayList object, however, it is set as a session attribute
(line 701).
 
Search WWH ::




Custom Search