Concurrent Stack Assignment
Contents
Previous Exercise
Recall that you have built a NotThreadSafeStack.
Motivation
We will modify our previous Stack solution, this time producing a thread-safe implementation of a Stack using synchronized methods.
Background
Synchronized methods are common way to enforce mutual exclusion on shared, mutable data.
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: | push peek pop |
|
package: | stack.concurrent.exercise | |
source folder: | student/src/main/java |
instance variables
The data structure instance variables from the NotThreadSafeStack will serve equally well here.
push
similar to NotThreadSafeStack's push method, with the added requirement of thread safety.
peek
similar to NotThreadSafeStack's peek method, with the added requirement of thread safety.
pop
similar to NotThreadSafeStack's pop method, with the added requirement of thread safety.
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