Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Locking & DBConnection (Thread) Pooling  RSS feed

Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For those that passed the SCJD exam or that are working on the assignment, could you please indicate how you implemented the database record locking and database connection pooling (or thread pooling) ?
In particular, I have the following 3 questions:
1) I am using a HashMap to keep track of locked records. The HashMap keys are an Integer wrappers for the record #'s (of the locked records) and the HashMap values are Strings for the ID's of the corresponding clients that locked the records. I synchronized on the HashMap whenever I need to lock/unlock a record. Does anyone see any problem with this?
2) For thread-poolingl, I use a DBConnection class that is a Runnable thread. DBConnection gets passed a Data object along with the client's ID to use for tracking locked records. The run() method of the DBConnection class listens for new Data objects and execute their run methods acting as their surogate threads and getting recycled (i.e. A fixed number of DBConnection threads are recycled instead of creating new ones each time I need a DBConnection). I this a good approach to thread/database connection pooling?
3) How can I use the Observer pattern for the time consuming and resource intensive file operations in the Data class?
Thank you for all you help in advance.
Timothy Nguyen

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!