Week 4 - Singleton Session Beans Flashcards
Why use a singleton session bean?
To create a shared instance for all clients.
What is AtomicInteger?
some data structures from java.util.concurrent are thread-safe
AtomicInteger shared = new AtomicInteger(1);
public int increment() {
return shared.incrementAndGet();
}
What is a problem with using synchronized or locks for concurrency?
Bottlenecks
What is container-managed concurrency?
The default for singleton session beans.
Annotate class or methods with:
@jakarta.ejb.Lock(locktype)
locktype is an enum defined in jakarta.ejb.LockType
READ allows concurrent access to all requests
WRITE (default) defines lock that can be held by one
thread at a time
What is bean managed concurrency?
@jakarta.ejb.ConcurrencyManagement(BEAN)
make bean thread-safe manually using tools from java.util.concurrent
What other session bean has the same lifecycle as a singleton session bean?
Stateless session bean
(Does not exist OR method-ready)
What are value objects (data transfer objects)?
DTOs (Data Transfer Objects) are simple objects that carry data between different parts of a system. They are especially useful when transferring data reliably, ensuring that values (like a URL) remain consistent and unmodified during the transfer. Since some types, like URLs, are mutable, it’s important to copy them before passing them along to prevent unexpected changes.
Singleton beans are suitable for caching RSS feeds (T or F)
T
What is an RSS feed?
An RSS feed (Really Simple Syndication) is a way for websites to share their latest content with you automatically, without you needing to visit the site directly.