Represent a Queue in the ThreadPool.
If pass in a Queue object when you schedule() your job, then your job will be scheduled on that particular queue. This does not in any way affect the order in which jobs are executed. Use priority for that. Instead, if you later delete your Queue, any jobs scheduled on that Queue will not be executed any more.
When you delete the Queue, your thread will block until any jobs currently being executed have finished. I.e. after the Queue is destroyed, no jobs will be running any more, nor will any be run in the future. This can cause deadlocks if a job running on a ThreadPool tries to destroy its own queue.
To avoid deadlock, you should make sure that jobs running on the ThreadPool only have references to WeakQueue objects, or you should create your Queue using createAsync(). This will do the actual Queue destruction on a separate thread. As a result, after the last reference to the Queue object goes out of scope, jobs on the Queue may continue running for some time.
- Note
- If you delete the Queue, the associated jobs will not actually be deleted. Instead, when the time comes to execute the job, a check is done whether the Queue still exists. If it doesn't, the job is silently discarded.