https://github.com/jmnarloch/lazy
Java 8 lazy type
https://github.com/jmnarloch/lazy
java java-8 lazy library
Last synced: 2 months ago
JSON representation
Java 8 lazy type
- Host: GitHub
- URL: https://github.com/jmnarloch/lazy
- Owner: jmnarloch
- License: apache-2.0
- Created: 2017-02-05T01:11:13.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-10T05:31:52.000Z (about 8 years ago)
- Last Synced: 2025-01-07T13:14:50.516Z (4 months ago)
- Topics: java, java-8, lazy, library
- Language: Java
- Size: 80.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Java 8 Lazy type
> General purpose, thread safe and high performance lazy type
[](https://travis-ci.org/jmnarloch/lazy)
[](https://coveralls.io/github/jmnarloch/lazy?branch=master)## Setup
Add the library to your project:
```xml
io.jmnarloch
lazy
1.0.0```
## UsageUsage is really simple, you can create a lazy reference to any object. The instance is being provided by a `Supplier`.
The `Supplier` will be evaluated upon the first call of the `get` method.```java
final Lazy value = Lazy.create(() -> new ComplexObject());// get the object instance
ComplexObject object = value.get();
```The implementation is guaranteed to be thread safe.
## Performance
The actual `Lazy` type implementation uses lock free implementation giving it very good performance compared to lock
variant whenever it uses the `synchronized` Java keyword or directly `Lock` type.| Benchmark | Mode | Cnt | Score | Error | Units |
| --------- | ---- | --- | ----- | ----- | ----- |
| LazyBenchmark.benchmarkGet | thrpt | 20 | 271440905,189 | ± 2721909,603 | ops/s |
| LazyBenchmark.benchmarkInitializeAndGet | thrpt | 20 | 274012023,081 | ± 1720484,338 | ops/s |## License
Apache 2.0