Currently I have a global static MySqlConnection connection; which is shared across threads (bad, I know) but I lock while opening new connections or closing old ones and only do so if the thread is the first that has been created or the last that was left (I also determine this by a static int MySqlConnected).
Currently it gets mixed up for some reason, what is the problem with my setup?
it gets mixed up? Could you explain what is your error? I have a feeling about it