Difference between revisions of "Concurrent Stack Assignment"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
=Previous Exercise= | =Previous Exercise= | ||
− | [[Stack_Assignment|NotThreadSafeStack]] | + | Recall that you have built a [[Stack_Assignment|NotThreadSafeStack]]. |
=Motivation= | =Motivation= |
Revision as of 19:41, 7 April 2023
Contents
Previous Exercise
Recall that you have built a NotThreadSafeStack.
Motivation
We will build a thread-safe implementation of a Stack using synchronized methods.
Background
Implicit Locks
Code To Implement
ConcurrentStack
To be @ThreadSafe, one must hold intrinsic lock (via synchronized) on the ConcurrentStack instance for each of the methods which read and/or write to mutable data.
class: | ConcurrentStack.java | |
methods: | constructor push peek pop |
|
package: | stack.concurrent.exercise | |
source folder: | student/src/main/java |
constructor and instance variables
Be sure to initialize whatever state you need to implement a mutable thread-safe Stack.
push
peek
pop
Testing
class: | __ConcurrentStackTestSuite.java | |
package: | stack.concurrent.exercise | |
source folder: | testing/src/test/java |
Pledge, Acknowledgments, Citations
file: | concurrent-stack-pledge-acknowledgments-citations.txt |
More info about the Honor Pledge