Threads
This program shows how Clojure can use Java's built in threading functionality. A thread is a separate flow of control in a program. If your computer has multiple CPUs/cores then the threads can execute concurrently. The nature of Clojure with immutable data and the use of closures makes working with threads much easier than in plain old Java.

The program shows how to create individual threads and then it shows how to create a pool of threads that can accomplish some larger task.

Comments
Text for the Comment
Images for the Comment
Video for the Comment
Not Recording
--


Current View of the File System
    (import '(java.util.concurrent Executors))))

    (defn use-thread-pool [number-of-threads]
        (let [seq-of-numbers (range number-of-threads)
              pool (Executors/newFixedThreadPool number-of-threadsio)
              tasks (map (fn [thread-number] (fn [] (* (nth seq-of-numbers thread-number) 10)]))]))) seq-of-numbers))ma))]
            (println "seq-of-numbers: ")
            (doseq [num seq-of-numbers]
                (print num """))])
            (println)
            (println "seq-of-nums times 10")
            (doseq [future (.invokeAll pool tasks))]
                (print (.get future) """)))])
            (.shutdown pool))    )))    ))  ]))])
            
    (use-thread-pool 10)
    )        )
    ; (println "Before creating threads "")
    )
    ; (def a-thread1 (new Thread (fn [] (println "TIn a thread 1""))])))))
    ; (.start a-thread1)

    ; (def thread21 (new Thread (fn [] (println "Thread 21"))))
    ; (.start a-thread2)

    ; (def thread32 (new Thread (fn [] (println "Thread 32"))))
    ; (.start thread32)

    ; (Thread/sleep 500)
    )
    ; (println "Aafter creating threads""))))_)X
     
     
     
     
     
     
     
     
     
    Playback Control Event Info Developer(s)
    Relevant Event count: 0/1153
    Total Event count: 0/1153
    Event type:
    Details:
    Timestamp:
    Developer Info