Problems with sql
Mariadb
The Best thing is that it only accous like 1 out of 20 times
23 Replies
⌛
This post has been reserved for your question.
Hey @LinusHuck! 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.
Are you using that from multiple threads?
Interestingly, it seems to fail at
stmt.setInt(2, lastMessageID);
which means the setString
might should be successful
Does that exception always happen?its runTaskTimerAsynchronously
around 1 out of 20
yeah that may be the issue
that is not thread safe
how can i make it thread save?
https://paste.ofcode.org/KUs42E6wXsv494NjYBTJjN
it is possible that:
- thread 1 calls
getConnection()
.
- thread 2 executes getMessages
which calls getConnection()
inside. This returns the same connection as thread 1
- thread 1 closes the Connection
- thread 2 executes setInt
- This fails because the Connection
is closed
Don't attempt to cache connectionsI see thanks i will try it
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Do you always close the
Connection
s you get from getConnection
?actually never
you are doing it here
the try-with-resources closes the connection
oh i thought you mean conection.close()
then prob most of the time
so like this?
the try-with-resources calls
close()
at the end
Are you always doing it?
If yes, you can just do
lets say i dont close it somewhere will it hurt?
yes
forgetting to close it results in the DB connection staying open
even if you cannot use it any more
is there a thing like close after 5sec if not used?
which needs memory and resources on both the Java and DB side
and if you do it too often, you have many open connections until you reach the connection limit
normally not but it might be different in your case
Like what if some operations takes more than 5s? Would you want the DB connection be closed during an operation?
But you can use your IDE to find all calls to
getConnection
and then make sure all of them ensure it being closedOk thanks
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Post Closed
This post has been closed by <@430770874929381386>.