Greetings, I am curious if there is someway to check if ArrayBlockingQuery query is currently locked ?
The reason for this : I have a server which is listens to a socket, receives parameters, process them and then returns some result to client. That server(let say it is server A) while processing parameters open session with other server( server B) and then send info to B. Only one session can be created when connecting to B, but A can accept several client connection. Because of that ArrayBlockingQueue is used to stored that parameters and some other thread run through the queue and send them one by one to B.
I need to do that functionality – when ArrayBlockingQueue is empty and nothing is processed in current moment and client data send to A then process immediately – send data to B server, process response from B and then A return response to client if ArrayBlockingQuery is not empty and something is processed then just add parameters to queue and send other response from A to client. Thats why i need to know if there is a way to check if ArrayBlockingQueue is locked or queue element currently processed by thread.
Thank you!
Is there any reason you don’t just use a Lock as this is designed for protecting resources which can only be used in one thread at a time.
This ensures server B will only be use in one thread at a time and you don’t need to add anything to a queue.
Not sure what a
ArrayBlockingQueryis, nor does google. Do you meanArrayBlockingQueue?An ArrayBlockingQueue is not locked for very long, so this information isn’t very useful. However you could obtain the lock via reflection.
You appear to be over thinking your solution.
You want to ensure that server B only get a connection one at a time, and you are using a queue to do this, however you want to way to by-pass this, but this means discarding your one at a time principle.