File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes How to unlock a record after its been deleted? 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 "How to unlock a record after its been deleted?" Watch "How to unlock a record after its been deleted?" New topic
Author

How to unlock a record after its been deleted?

Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

Good Evening Guys,

I know I've been posting like crazy here and I thank you for your patience. Im running tight on time. I need to complete the assignment by December 25th and I have yet to submit my code. As a point of interest, how long do Oracle take before they indicate whether or not you need to sit the essay?

Back to my question, what is the standard way to handle deletion of a record?

lock
delete
unlock

If this is so, how can something thats been deleted be unlocked?

G


OCPJP 6, OCMJD
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2267
    
    3

Howd, Glen!

Well, in my case, I had a Map<Integer, Long> where I keep track of what records are locked. The key is the record number, and the value is the id of the client that owns the lock. I also had a Map<Integer, Room> that represented the database records. After deleting a record, its corresponding entry is removed from the Map that represents the database records. And to unlock a record, its corresponding entry is simply removed from the Map that keeps track of the locked records, so there is not problem if it was already deleted.

So everything is handled virtually, in memory. When the application finishes, the Map that represents the database records is flushed to the .db file.

Regarding the essay, when I took this certification, we had to take the essay after submitting the assignment. We just got a voucher for that and scheduled it online in a Prometric center. I think you still have to do it nowadays. For more information, please take a look here.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

Hey Buddy,

Thanks for the reply. My difficulty now is, what to do with the threads that are waiting on a record that just got deleted? From your scenario, I think you have come across this issue too.

For example, thread 5 is waiting to lock record 26.
thread 4 deletes record 26.

thread 5 wakes up and checks if the record still exists in
Map<Integer, Long> where I keep track of what records are locked
. If not, it throws a record not found exception.

When I do the above, I see IllegalMonitorExceptions and deadlock sometimes occurrs.

EDIT:The thing is, when I run your test class with updateRandom,Update1,Find and Create, everything runs smoothly. If I run the delete threads too, thats when I see IllegalMonitorExceptions and deadlock.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1510
    
    5

Hi Glen,

IllegalMonitorStateException typically happens when you invoke wait/notify method without holding a lock on that object. Is this the case in your code?

Also, check if you are releasing the locks in 'finally' block. If not done, then it is very typical scenario in which a lock is obtained, and due to some exception, it is never released. This may further lead to deadlock.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

Thanks Chaps. You've inspired a comeback.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

I see you where in good hands when I was enjoying some sun & sea, but now I'm back


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

Roel De Nijs wrote:I see you where in good hands when I was enjoying some sun & sea, but now I'm back


As far as I can tell 99% of the hands around here are good.

I hope your holiday went well. You find me in the middle of doing my choices.txt file. I've been reading through the past pages on this site for ideas of what to include/not to include. I came across your good self's list of contents. Im wondering how high/low level to get?

Do I keept it as a design pattern level or do I go down low and discuss why I used a LinkedHashMap over a HashMap?

Thanks Roel.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

Glen Iris wrote:I hope your holiday went well.

Yes, although the weather was in the 1st half a bit less than expected, I really enjoyed it and had a great time

Glen Iris wrote:Do I keept it as a design pattern level or do I go down low and discuss why I used a LinkedHashMap over a HashMap?

The choices.txt (and the essay exam) are designed to make "sure" that you developed the assignment yourself and not some java whizz kid next door. So the more detailed your information is, the better of course. I mentioned class names, method names and data member names. Both in the decisions document as on the essay exam. So i would opt for low level, of course only appropriate parts. It's useless to discuss the need of every variable and why you chose that particular type.
Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

Roel De Nijs wrote:Yes, although the weather was in the 1st half a bit less than expected, I really enjoyed it and had a great time



At least it ended on a high and I bet even the first half was better than Belgium (and Ireland) at this time of year anyway!

Im running at about 3800 words. Do you remember roughly your word count?
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

Glen Iris wrote:I bet even the first half was better than Belgium (and Ireland) at this time of year anyway!



Glen Iris wrote:Do you remember roughly your word count?

No. But I had a quick glance: exactly 5613 words
Dennis Grimbergen
Ranch Hand

Joined: Nov 04, 2009
Posts: 143

I used 4934 words. Just to give an indication.
Quantity is not automatically quality

Just show them that you were able of analyzing a problem and solve it a certain way that you can explain.


SCJP, SCWCD, SCJD
Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

thanks Dennis.

I think my final count was 4500ish. I had to submit on tuesday evening as I was out of time.I sat the essay yesterday morning. the 6-8 week waiting game begins.in the mean time I have a few threads to tidy up in here.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

Glen Iris wrote:the 6-8 week waiting game begins.

Based on recent candidate stories, I think you'll get your result much faster than this period.
Dennis Grimbergen
Ranch Hand

Joined: Nov 04, 2009
Posts: 143

My guess would be that you don't have to wait 6-8 weeks.
Since the course requirement the amount of participants for this exam has dropped extensively. I submitted somewhere in June and got my result in november. During that time there were a lot of developers who wanted to finish this exam before the course requirement date (and the transition to Oracle and/or PearsonVue was messy at that time).

Next weekend you have your results....at least that would be my wild guess. Until that time...relax and have a beer.

lol roel was faster
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2267
    
    3

Glen Iris wrote:I sat the essay yesterday morning.


Good luck, champion! I'm sure you're going to do well on this one
Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

so is there a course attendance requirement now? if so, when did it come in?
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

I have no idea, because I finished when this requirement didn't exist

But based on this link you have to complete a form which Oracle uses to verify you followed one of the required courses. When you decide to follow one, is completely up to you.
Guillaume Drouet
Ranch Hand

Joined: Apr 16, 2012
Posts: 36
Glen Iris wrote:Thanks for the reply. My difficulty now is, what to do with the threads that are waiting on a record that just got deleted?


Hi,

just to give additional value to this topic, I share how I solved the same issue : http://www.coderanch.com/t/584411/java-developer-SCJD/certification/notify

I remember that it was very hard for me to detect why some deadlocks still occured at the end of my development. The issue is related to some threads waiting for a record that is deleted by the one which owned the lock. What I have done is to call notifyAll() in my delete-method for all threads which are waiting for the lock (1 lock per record is possible in my solution). Once the thread has been awaken, it just raise a RNFE because the record is not in the memory cache anymore.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to unlock a record after its been deleted?