Welcome to the Ranch!
Mike Skruf wrote:Why do threads numbers (atleast in my case) start with 9 and up?
There are a number of threads outside your control that the JVM uses for things (like initialization, garbage collection, and other things).
Why does the while(Thread.activeCount()>1) then wait for all the threads to finish doing their work before closing the DB connection?
You shouldn't count on that working... it isn't the correct way to do things. The safe way would use some form of inter-thread communication to signal the work is done.
I'm not quite happy with the way I disconnect from the DB (waiting for the while function to exit) - any suggestions on how to make that piece a bit better?
1) Put the work in a try {} clause
2) Add some form of inter-thread signalling to determine when all your threads are done. (see
this tutorial for some ideas on how). This would be done inside the try clause
3) Disconnect the DB in a finally{} block after the try{}.
Is there a new instance of handleDB() created in every thread, or is there only one used throughout the application? (is there a way of seeing it myself?)
The easiest way to see for yourself is to read the code. Where is
new handleDB() called? How many times does it get called? How is/are it/they used?
If you can't figure it out then you could add some things to help:
- System.out.println() the handleDB used in each thread. Look at the output to see if each thread puts out the same thing.
- Use a profiler
Why does counter (if written in a separate file) return random numbers? I'd like it to return the ammount of times an entry has been made in the DB. If I wrote the code in the same file where I have my main, I could use the static class modifier and it worked - in a separate file it doesnt :/
It isn't because you moved where the class is, it is because you are changing the value of the counter in an unsafe manner. Read that tutorial I gave you.