File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Multithreading madness! ;) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Multithreading madness! ;)" Watch "Multithreading madness! ;)" New topic

Multithreading madness! ;)

Adam Roberts
Ranch Hand

Joined: Mar 18, 2002
Posts: 71
Ok so I'm almost done with this thing but I've hit a little bit of a road block.
My locking mechanism works great, except during the shutdown process. I've tried several things and still end in dead lock or other errors. I'm using the wait() method to handle client requests and timers to dispose of stale locks. When the server calls lock(-1) and encounters a lock, it of course hits wait(). This causes the server thread to stop(well, they are waiting) the timers, and the locks never die.
I've tried doing something like

but this creates odd errors. First of all, when I attempt to shut the DB down with no locks on it, it only locks a seemingly random number of records. Second, whenever it encounters a lock( and a wait() request ), the thread simply dies.
Any ideas here?
I had another thought about creating a administrator client that would be used to lock the database, but wonder if I'll get docked points for the work around as I would have two programs running for the server.
Any thoughts would be helpful
[ April 11, 2002: Message edited by: Adam Roberts ]

Adam Roberts - SCJP2, SCJD<br />insert witty something here
Peter den Haan
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
You might well be on the right track with threading problems, but it is very hard to say anything without seeing code. Can you cut the relevant code down to a postable size?
- Peter
Adam Roberts
Ranch Hand

Joined: Mar 18, 2002
Posts: 71
Heres the lock function

...and the lockAll()

And finally the thread attempt(nested in an actionListener)

Bhuvan mehra
Ranch Hand

Joined: Mar 29, 2002
Posts: 69
hi Adam,
instructions about lock() method says,
if the method is called with an argument of -1, the entire db should be locked.
Adam Roberts
Ranch Hand

Joined: Mar 18, 2002
Posts: 71
Thats taken care of in my data class...
If its -1, it calls lockAll()
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
Can you try locking the object that contains the lock method you've posted instead of the objects it uses.
Adam Roberts
Ranch Hand

Joined: Mar 18, 2002
Posts: 71
Oooh :0
Thanks for the idea
Possibly just have a boolean value to redirects calls/throws an exception after the flag has been switched?

Any more ideas would be appreciated and thanks Sai
I agree. Here's the link:
subject: Multithreading madness! ;)
It's not a secret anymore!