#singleton Clear
Tags #php #kotlin #bash #go #sql #rust #typescript #html #java #python #files #utils #strings #http #concurrency #async #json #arrays #security #types #crypto #database #dates #format
Bash flock — Cron-Singleton Lock
Prevent two copies of a cron job from running simultaneously. flock takes an FD to a lock file; if the lock is held, the second invocation exits immediately.
Kotlin object Declaration — Singleton
`object` declares a thread-safe lazy singleton. Built into the language — no `private constructor + getInstance()` boilerplate. Also: anonymous `object : Interface { … }` for one-shot instances.
PHP Singleton Trait
A reusable trait that turns any class into a lazily-instantiated singleton with a single ::instance() accessor. Throws on clone/wakeup to prevent accidental duplication.
Go sync.Once — Lazy One-Time Initialization
Run a function exactly once, even from many goroutines. Standard pattern for lazy singletons, expensive setup, and one-time configuration.
TypeScript Lazy Singleton (no class)
Lazily construct an expensive object exactly once, with TypeScript inferring the return type from the factory. Cleaner than the class-trait singleton pattern for module-scoped state.
Java Singleton via enum
`enum` with a single value is the simplest correct singleton implementation: lazy, thread-safe, serialization-safe, reflection-safe. Joshua Bloch's recommendation in Effective Java.