Skip to content

Instantly share code, notes, and snippets.

@SaschaMoellering
Created December 4, 2013 22:28
Show Gist options
  • Save SaschaMoellering/7796766 to your computer and use it in GitHub Desktop.
Save SaschaMoellering/7796766 to your computer and use it in GitHub Desktop.
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.
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