Asyncronous task queue
I have one thread that delegates tasks over to another thread, which runs those tasks in a queue. These tasks are blocking tasks (database), that I want to be run in the correct order, first in first out.
Currently using BlockingQueue, but when testing it using junit, it can freeze the whole test. That's because after each test, this thread is waited on until it finishes. I have not found a good way to enable/disable the queue
How would one do this properly?
32 Replies
⌛
This post has been reserved for your question.
Hey @Thorinwasher! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
Can you show the relevant code?
Just the code that's necessary to reproduce the issue
Sure, don't laugh at it though 🤣
And if possible, please also show where exactly the code blocks the tests - Is it somewhere during the test or after running the tests?
Oh, too large...
I am fairly sure your code is better than the code of many other people - after all you are writing tests
you can also try to upload the files
Good point, I'm not educated enough in concurency though
Ah
or ideally only include the relevant code
let me do that then
concurrency is hard
The most complicated chapter of the JVM specification (which specifies how JVMs have to work) is pretty much about what should happen in multithreaded environments
I think you need more info than that though
Can you show the test and where it blocks?
Sure, this is one test that blocks everything, but that relates to the test that ran before it
It's quite layered though