File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to unlock a record after its been deleted?

 
Glen Iris
Ranch Hand
Posts: 168
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Glen Iris
Ranch Hand
Posts: 168
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1557
5
Eclipse IDE Java Linux
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Glen Iris
Ranch Hand
Posts: 168
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Chaps. You've inspired a comeback.
 
Roel De Nijs
Sheriff
Posts: 9105
75
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see you where in good hands when I was enjoying some sun & sea, but now I'm back
 
Glen Iris
Ranch Hand
Posts: 168
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9105
75
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 168
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9105
75
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 159
IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Glen Iris
Ranch Hand
Posts: 168
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9105
75
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 159
IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2271
3
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 168
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so is there a course attendance requirement now? if so, when did it come in?
 
Roel De Nijs
Sheriff
Posts: 9105
75
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic