Package com.prineside.tdi2
Class Threads
java.lang.Object
com.prineside.tdi2.Threads
Manages all of the (multi)threading stuff
 Also triggers the EngineCrash event if it catches an unhandled exception in any of the configured
 threads
 Stores crash report in a file and provides methods to get the previous crash report on the next
 game start. Crash-handling behavior may not look like fitting this class but it has a small
 footprint and is still related to threads. Not moved into a separate Manager to make it possible
 to read crash reports early, before Engine starts.
- 
Nested Class Summary
Nested Classes - 
Method Summary
Modifier and TypeMethodDescription<T> voidasyncConcurrentLoop(T[] elements, int start, int count, IntObjectConsumer<T> handler, Runnable onFinish, ObjectConsumer<Exception> onError) <T> voidconcurrentLoop(Array<T> elements, IntObjectConsumer<T> handler) Run the loop on multiple threads.<T> voidconcurrentLoop(T[] elements, int start, int count, IntObjectConsumer<T> handler) createThread(String name, Runnable job, boolean shouldCrashTheGame) Create new daemon thread and handle its uncaught exceptions.static Threadsi()static voidvoidpostRunnable(Runnable runnable) Executes the runnable with Gdx.app.postRunnable() and stores the stacktrace to print a detailed info if runnable throws an exception.voidpostRunnableOnce(Runnable runnable) Note: for ui-specific tasks (like updating some menu in response to in-game event) use UiManagervoidRun a job on another thread.voidrunAsync(Runnable runnable, ObjectConsumer<Exception> onError) voidrunOnMainThread(Runnable runnable) Runs the runnable immediately if called from the main thread.voidrunOnMainThreadBlocking(Runnable runnable, float timeoutSeconds) Run some task on the main (rendering) thread and block current thread till the task is done.static <T> voidsort(Array<T> array, Comparator<? super T> comparator) static <T> voidsort(T[] array, int start, int size, Comparator<? super T> comparator) static <T> voidsort(T[] array, Comparator<? super T> comparator) voidsynchronize(Object lock, Runnable runnable) voidtryCatch(Runnable runnableToTry, ObjectConsumer<Throwable> onError) voidtryFinally(Runnable runnable, Runnable onFinally)  
- 
Method Details
- 
i
 - 
runOnMainThreadBlocking
Run some task on the main (rendering) thread and block current thread till the task is done. Will run on the same thread immediately if called from the main thread. Similar to Gdx.app.postRunnable() but won't delay the execution if called from the main thread and will pause current thread till done.- Parameters:
 runnable- task to run on the main (rendering) threadtimeoutSeconds- max time (in seconds) the task may take. In case of timeout, the task will continue to run on the main thread
 - 
runOnMainThread
Runs the runnable immediately if called from the main thread. Posts a runnable to GDX if not in a main thread. Similar to Gdx.app.postRunnable() but won't delay the execution if called from the main thread. If you need to run something at the exactly next frame, use postRunnable() - 
runAsync
Run a job on another thread. Uses a thread pool. - 
runAsync
 - 
sort
 - 
sort
 - 
sort
 - 
postRunnable
Executes the runnable with Gdx.app.postRunnable() and stores the stacktrace to print a detailed info if runnable throws an exception. Writes to log if runnable takes more than 80ms to execute - 
postRunnableOnce
Note: for ui-specific tasks (like updating some menu in response to in-game event) use UiManager - 
createThread
Create new daemon thread and handle its uncaught exceptions. Thread must be started with start()- Parameters:
 name- name of the threadjob- job to be done by the threadshouldCrashTheGame- if true, uncaught exceptions in this thread will stop the game- Returns:
 - new thread awaiting to be started
 
 - 
synchronize
 - 
tryFinally
 - 
tryCatch
 - 
concurrentLoop
Run the loop on multiple threads. Blocks the thread it is being called from. If any exception happens during the loop, the game will stop. - 
concurrentLoop
 - 
asyncConcurrentLoop
public <T> void asyncConcurrentLoop(T[] elements, int start, int count, IntObjectConsumer<T> handler, Runnable onFinish, ObjectConsumer<Exception> onError)  - 
main
 
 -