API for singleton - clojure-contrib v1.2 (stable)

by Stuart Sierra

Full namespace name: clojure.contrib.singleton

Overview

Singleton functions

Public Variables and Functions



global-singleton

function
Usage: (global-singleton f)
Returns a global singleton function.  f is a function of no
arguments that creates and returns some object.  The singleton
function will call f just once, the first time it is needed, and
cache the value for all subsequent calls.

Warning: global singletons are often unsafe in multi-threaded code.
Consider per-thread-singleton instead.
Source


per-thread-singleton

function
Usage: (per-thread-singleton f)
Returns a per-thread singleton function.  f is a function of no
arguments that creates and returns some object.  The singleton
function will call f only once for each thread, and cache its value
for subsequent calls from the same thread.  This allows you to
safely and lazily initialize shared objects on a per-thread basis.

Warning: due to a bug in JDK 5, it may not be safe to use a
per-thread-singleton in the initialization function for another
per-thread-singleton.  See
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5025230
Source
Logo & site design by Tom Hickey.
Clojure auto-documentation system by Tom Faulhaber.