On Thu, Nov 12, 2009 at 07:50:31AM -0800, Sean Devlin wrote:

>(defn daemon
>  "Creates a new daemon thread and sets runnable to f"
>  [f]
>  (let [t (Thread. f)]
>    (do
>      (.setDaemon t true)
>      (.start t)
>      t)))
>
>And I tried calling
>
>user=>(daemon #(println "foo"))
>
>I get the thread back, but it does not appear to execute.  I've tried
>this on OSX and XP.  Does anyone know what I'm doing wrong?

I tried this on Linux, and prints "foo" once, which is what I would
expect.

If you want it to be period, though, you'll need to use something like
Executors/newSingleThreadScheduledExecutor to create a scheduler for
it.

I tried writing a periodic scheduler using agents (and a ref to manage
state).  Turns out that getting shutdown working robustly is actually
fairly tricky.  I recommend just using the scheduler available in
Java.

David

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to