Created
December 4, 2013 22:28
-
-
Save SaschaMoellering/7796766 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SharedData | |
extends java.lang.Object | |
Sometimes it is desirable to share immutable data between different event loops, for example to implement a cache of data. | |
This class allows instances of shared data structures to be looked up and used from different event loops. | |
The data structures themselves will only allow certain data types to be stored into them. This shields you from worrying about any thread safety issues might occur if mutable objects were shared between event loops. | |
The following types can be stored in a shareddata data structure: | |
String | |
Integer | |
Long | |
Double | |
Float | |
Short | |
Byte | |
Character | |
byte[] - this will be automatically copied, and the copy will be stored in the structure. | |
Buffer - this will be automatically copied, and the copy will be stored in the | |
structure. | |
Instances of this class are thread-safe. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We insist that the data stored is immutable in order to prevent race conditions that might occur if concurrent access to shared state was allowed. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment