Remarks
It is still recommended to use synchronized blocks to ensure thread safety. You can use the session object for synchronization, e.g.:
synchronized (session) {
Vector selections = (Vector) session.getAttribute(“selections”) ;
if(selections == null) {
selections = new Vector() ;
session.setAttribute(“selections”, selections) ;
}
}
As usual, the vending machine servlet will lead to a selection-viewing servlet when the user follows a suitable link.
These two servlets automatically share the same session object, and thus session information, because they are in the same servlet context.