Class ThreadPool

java.lang.Object
All Implemented Interfaces:
Proxy

@Generated("io.github.jwharm.JavaGI") public class ThreadPool extends ProxyInstance
The GThreadPool struct represents a thread pool.

A thread pool is useful when you wish to asynchronously fork out the execution of work and continue working in your own thread. If that will happen often, the overhead of starting and destroying a thread each time might be too high. In such cases reusing already started threads seems like a good idea. And it indeed is, but implementing this can be tedious and error-prone.

Therefore GLib provides thread pools for your convenience. An added advantage is, that the threads can be shared between the different subsystems of your program, when they are using GLib.

To create a new thread pool, you use new_(org.gnome.glib.Func, int, boolean). It is destroyed by free(boolean, boolean).

If you want to execute a certain task within a thread pool, use push(java.lang.foreign.MemorySegment).

To get the current number of running threads you call getNumThreads(). To get the number of still unprocessed tasks you call unprocessed(). To control the maximum number of threads for a thread pool, you use getMaxThreads(). and setMaxThreads(int).

Finally you can control the number of unused threads, that are kept alive by GLib for future use. The current number can be fetched with getNumUnusedThreads(). The maximum number can be controlled by getMaxUnusedThreads() and setMaxUnusedThreads(int). All currently unused threads can be stopped by calling stopUnusedThreads().