Skip to content

threads

Nuno Aguiar edited this page Apr 24, 2018 · 3 revisions

Threads.Threads

Threads.Threads() : Threads

Creates a new instance of a group of threads to manage.


Threads.addCachedThread

Threads.addCachedThread(aFunction) : String

Adds to the cached thread pool aFunction to be executed. Returns an UUID associated with the thread. The aFunction will receive the corresponding UUID as the first parameter. Note: it calls initCachedThreadPool if it wasn't previously and it won't work if any of the other start* of init* methods has been used previously.


Threads.addOpenAFShutdownHook

Threads.addOpenAFShutdownHook(aFunction)

Adds aFunction to try to execute whenever OpenAF is going to shutdown. The latest hook added will be the first to be executed until the first hook added.


Threads.addScheduleThread

Threads.addScheduleThread(aFunction, aDelay) : String

Adds to the scheduled thread pool aFunction to be executed within aDelay in ms. Returns an UUID associated with the thread. The aFunction will receive the corresponding UUID as the first parameter. Note: it calls initScheduledThreadPool if it wasn't previously and it won't work if any of the other start* or init* methods has been used previously.


Threads.addScheduleThreadAtFixedRate

Threads.addScheduleThreadAtFixedRate(aFunction, aRate) : String

Adds to the scheduled thread pool aFunction to be executed at a fixed aRate in ms. Returns an UUID associated with the thread. The aFunction will receive the corresponding UUID as the first parameter. Note: it calls initScheduledThreadPool if it wasn't previously and it won't work if any of the other start* or init* methods has been used previously.


Threads.addScheduleThreadWithFixedDelay

Threads.addScheduleThreadWithFixedDelay(aFunction, aDelay) : String

Adds to the scheduled thread pool aFunction to be executed at a fixed aDelay in ms. Returns an UUID associated with the thread. The aFunction will receive the corresponding UUID as the first parameter. Note: it calls initScheduledThreadPool if it wasn't previously and it won't work if any of the other start* or init* methods has been used previously.


Threads.addThread

Threads.addThread(aFunction) : String

Add a thread to call aFunction as callback. Returns an UUID associated with the thread. The aFunction will receive the corresponding UUID as the first parameter.


Threads.getNumberOfCores

Threads.getNumberOfCores() : number

Returns the number of cores identified by Java.


Threads.initScheduledThreadPool

Threads.initScheduledThreadPool(numberOfThreads)

Uses a thread pool situable for scheduled threads where you can specify the numberOfThreads to use (by defauly the number of cores). Note: it ignores any previous thread added using addThread; It won't work if any of the other start* or init* methods has been used.


Threads.start

Threads.start()

Start normally all threads added. Will wait for the end of execution of all threads. Note: it won't work if any of the other start* or init* methods has been used.


Threads.startAtFixedRate

Threads.startAtFixedRate(aTime)

Start all threads and restarts them at a fixed rate determined by aTime (in ms) independently of the time when the thread execution ends. Execution will stop upon Threads.stop.  Note: it won't work if any of the other start* or init* methods has been used.


Threads.startNoWait

Threads.startNoWait()

Start normally all threads added. Will not wait for the end of the execution of all threads. See Threads.waitForThreads for waiting for the execution of threads when needed or, in alternative, to Threads.start. Note: it won't work if any of the other start* or init* methods has been used.


Threads.startWithFixedRate

Threads.startWithFixedRate(aTime)

Start all threads and restarts them at a fixed rate determined by aTime (in ms) starting on the time when the thread execution ends. Execution will stop upon Threads.stop. Note: it won't work if any of the other start* or init* methods has been used.


Threads.stop

Threads.stop(shouldForce)

Stop all thread execution. If all threads need to be stopped immediately without waiting for the end of thread execution then used shouldForce = true.


Threads.sync

Threads.sync(aFunction)

Try to execute the aFunction in a synchronized method. Useful in parallel processing to safely access variables/resources shared between threads.


Threads.waitForThreads

Threads.waitForThreads(aTimeout) : boolean

Waits for all threads to finish during aTimeout period (in ms). Returns true if all threads stopped or false otherwise.

Clone this wiki locally